选中状态
下拉框、单选框和复选框选中状态判断可以通过is_selected()
和expected_conditions
下的element_to_be_selected()
方法
is_selected()
返回布尔值, element_to_be_selected()
与显式等待组合使用不满足则抛出异常
is_selected()方法
driver.find_element_by_xpath("//input[@id='select']").is_selected()
element_to_be_selected()方法
#!/usr/bin/python3.6
# coding=utf-8
# Author: 文
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
# 与显式等待组合使用
WebDriverWait(driver=driver, timeout=5, poll_frequency=0.5).until(
method=EC.element_to_be_selected(driver.find_element(By.id, "element")),
message="显式等待超时 元素依然为非选中状态