Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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_Selenium - Fatal编程技术网

Python 单击selenium中的复选框

Python 单击selenium中的复选框,python,selenium,Python,Selenium,我想点击这个复选框,我已经尝试了几乎所有的XPATH,但它不起作用 下面的类来自GoogleForms>IncludeForminEmail <div id="c9" class="quantumWizTogglePapercheckboxEl appsMaterialWizTogglePapercheckboxCheckbox docssharedWizToggleLabeledControl freebirdThemedCheckbox freebirdM

我想点击这个复选框,我已经尝试了几乎所有的XPATH,但它不起作用

下面的类来自GoogleForms>IncludeForminEmail

<div id="c9" class="quantumWizTogglePapercheckboxEl appsMaterialWizTogglePapercheckboxCheckbox docssharedWizToggleLabeledControl freebirdThemedCheckbox freebirdMaterialWidgetsToggleLabeledCheckbox isCheckedNext" jscontroller="EcW08c" jsaction="keydown:I481le;dyRcpb:dyRcpb;click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;" jsshadow="" jsname="gZKGbc" aria-label="Include form in email" tabindex="0" role="checkbox" aria-checked="false"><div class="quantumWizTogglePapercheckboxInk exportInk"></div><div class="quantumWizTogglePapercheckboxInnerBox exportInnerBox"></div><div class="quantumWizTogglePapercheckboxCheckMarkContainer"><div class="quantumWizTogglePapercheckboxCheckMark"><div class="quantumWizTogglePapercheckboxShort exportCheck"></div><div class="quantumWizTogglePapercheckboxLong exportCheck"></div></div></div></div>
它们都不起作用并生成错误:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(), 'appsMaterialWizTogglePapercheckboxCheckbox')]"}

“appsMaterialWizTogglePapercheckboxCheckbox”不是文本,而是类名。试一试

编辑

尝试使用
aria label
属性而不是
class
属性来选择正确的复选框:

"//*[@aria-label='Include form in email']"

您可能希望尝试按
id
进行搜索,因为这对于元素是唯一的

"//*[@id='c9']"

对于xpath,您正在查找文本,但您传入的文本实际上是一个类名。它确实有效,但选择了另一个复选框“收集电子邮件地址”,而不是特定的。@Karan请使用HTML更新两个复选框的问题,以便我可以提供唯一的选择。我已经编辑了上述内容。@Karan尝试更新xpath。复选框具有不同的
aria label
属性,因此您可以使用
[@aria label='Include form in email']
[@aria label='Collect email address']
来选择所需的复选框
"//*[contains(@class, 'appsMaterialWizTogglePapercheckboxCheckbox')]"
"//*[@aria-label='Include form in email']"
"//*[@id='c9']"