三、webdriver常用方法
# -*- coding:utf-8 -*-
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.baidu.com/")
# 返回元素的尺寸
size = driver.find_element_by_id("kw").size
print(size)
# 返回元素的文本
text = driver.find_element_by_id("bottom_layer").text
print(text)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
# driver.find_element_by_id("su").submit()
# 返回元素的文本
text = driver.find_element_by_id("bottom_layer").text
print(text)
# 返回元素的属性值
attribute = driver.find_element_by_id("kw").get_attribute('type')
print(attribute)
# 返回元素的结果是否可见,bool类型
result = driver.find_element_by_id("kw").is_displayed()
print(result)
driver.quit()
网友评论