from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
domestic=driver.find_element_by_xpath('//*[@id="chkGraphic_0"]')
if domestic.is_selected():
#uncheck
driver.execute_script("arguments[0].click();",domestic)
使用
execute_script()
并不是一种理想的方法来点击复选框来选择/取消选择它。相关的HTML DOM会帮助我们构建一个规范答案。但是,要选择/取消选择复选框,您需要为element_to_be_clickable()
导入WebDriverWait,并且可以使用以下任一解决方案:使用
CSS_SELECTOR
:使用
XPATH
:注意:必须添加以下导入:
如果要先选中复选框是否已选中,请使用
.is_selected()
:相关问题 更多 >
编程相关推荐