python自动化测试——元素操作

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()
driver.get("https://www.***.cn")

#获取文本
text = driver.find_element(By.CSS_SELECTOR,"***").text

#获取属性值
value = driver.find_element(By.CSS_SELECTOR,"***").get_attribute("value")

#是否可见
displayed = driver.find_element(By.CSS_SELECTOR,"***").is_displayed()

#是否勾选
selected = driver.find_element(By.CSS_SELECTOR,"***").is_selected()

#输入文本
driver.find_element(By.CSS_SELECTOR,"***").send_keys("***")

#清除文本
driver.find_element(By.CSS_SELECTOR,"***").clear()

#单击元素
driver.find_element(By.CSS_SELECTOR,"***").click()

#下拉框选择
ele = driver.find_element(By.CSS_SELECTOR,"***")
#根据value选择
Select(ele).select_by_value("value")
#根据text选择
Select(ele).select_by_visible_text("text")
#根据索引选择0开始
Select(ele).select_by_index(index)

driver.quit()

 

posted @ 2019-02-15 14:58  OTAKU_nicole  阅读(321)  评论(0编辑  收藏  举报