WebDriver获取元素信息常用方法_新手入门笔记
以百度为例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/div/div/div/div/div/ul/li/a').text
print(text)
#获取元素属性值
att =driver.find_element(By.XPATH,'/html/body/div/div/div/div/div/div/ul/li/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()
页:
[1]