Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python selenium-单击复选框,该复选框也有一个下拉文本_Python_Python 3.x_Selenium - Fatal编程技术网

Python selenium-单击复选框,该复选框也有一个下拉文本

Python selenium-单击复选框,该复选框也有一个下拉文本,python,python-3.x,selenium,Python,Python 3.x,Selenium,我想标记一个复选框,但问题是复选框附近的文本也包含一个折叠链接,因此每当我尝试并单击它时,只显示下拉文本,因此复选框不会被标记。 我已尝试使用单击复选框 driver.find_element_by_xpath(".//*[contains(text(), 'example_text_positiond_next_to_checkbox')]").click() 但是,如上所述,这只会单击文本,然后继续显示折叠的文本 HTML代码片段是(我希望没有遗漏任何重要部分) 我

我想标记一个复选框,但问题是复选框附近的文本也包含一个折叠链接,因此每当我尝试并单击它时,只显示下拉文本,因此复选框不会被标记。 我已尝试使用单击复选框

driver.find_element_by_xpath(".//*[contains(text(), 'example_text_positiond_next_to_checkbox')]").click()
但是,如上所述,这只会单击文本,然后继续显示折叠的文本

HTML代码片段是(我希望没有遗漏任何重要部分)


我曾想过要单击文本左侧的一些空白,但不太确定如何做到这一点。 欢迎任何建议

那是盒子:

这可以通过css选择器来完成,因为在DOM中没有直接的方法来检查该复选框

driver.find_element(By.CSS_SELECTOR,"input#customCheck1.custom-control-input").click()
试试下面的css

input#customCheck1.custom-control-input
您可以使用任何属性来查找元素,上述具有“for”属性的定位器将起作用。您可以使用xpath或css

XPATH等价:

//*[@for="customCheck1"]

是否有指向taht网站的链接是的-如果添加一个链接(还有一个英文选项),会更有帮助,只需注意,它会因过度使用而不断崩溃。请添加您感兴趣的复选框的屏幕截图,为什么不能使用xpath完成此操作
//input[@id=“customCheck1”并包含[@class,“custom control input”]]
是CSSGo到该网站的xpath等价项>在chrome上打开开发工具>CTRL+F如果粘贴到xpath上面,则未选择任何元素,如果放置css\U选择器,则会看到该复选框高亮显示。“xpath将不起作用”您的xpath错误在于两个不同的语句::after不是xpath符号,而是CSS。这些元素称为伪元素。
//输入[@id=“customCheck1”并包含(@class,“自定义控件输入”)]
driver.get("https://corona.health.gov.il/en/green-pass/")

driver.find_element_by_css_selector('[for="customCheck1"]').click()
input()
//*[@for="customCheck1"]