|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
以百度为例
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from time import sleep
- driver =webdriver.Chrome()#实例化浏览器对象
- driver.get('https://www.baidu.com/')
- #size获取元素大小
- size = driver.find_element(By.ID,'kw').size
- print(size)
- #text获取元素文本
- text =driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[5]/div/div/div[3]/ul/li[1]/a').text
- print(text)
- #获取元素属性值
- att =driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[5]/div/div/div[3]/ul/li[1]/a').get_attribute("href")
- print(att)
- #判断元素是否可见
- diplay=driver.find_element(By.ID,'hotsearch-content-wrapper').is_displayed()
- print(diplay)
- #按钮是否可用
- enabled=driver.find_element(By.XPATH,'//*[@id="hotsearch-refresh-btn"]/span').is_enabled()
- print(enabled)
- #判断 是否被选中 .is_selected()
复制代码 |
|