1

I want to click this checkbox, I have tried almost all the XPATH but it's not working.

The following class is from the GOOGLE Forms > Include FORM in Email

<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>

There's another class which is similar to above but has a different checkbox.

<div id="c6" 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="JUdOvc" aria-label="Collect email addresses" 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>

I tried with the following:

search = driver.find_element_by_xpath("//*[contains(text(), 'appsMaterialWizTogglePapercheckboxCheckbox')]")

None of them works and generates the error:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(text(), 'appsMaterialWizTogglePapercheckboxCheckbox')]"}
1
  • 1
    With your xpath you are looking for text, but the text that you pass in is actually a class name. Commented Jan 27, 2021 at 12:14

2 Answers 2

2

'appsMaterialWizTogglePapercheckboxCheckbox' is not a text, but class name. Try

"//*[contains(@class, 'appsMaterialWizTogglePapercheckboxCheckbox')]"

Edit

Try to use aria-label attribute instead of class attribute to select correct checkbox:

"//*[@aria-label='Include form in email']"
Sign up to request clarification or add additional context in comments.

3 Comments

It does works but selects another checkbox "Collect email addresses" not the particular.
@Karan please update your question with HTML for both checkboxes so I can provide with unique selector
@Karan try updated XPath. Checkboxes have different aria-label attributes, so you can use [@aria-label='Include form in email'] and [@aria-label='Collect email addresses'] to select required checkbox
0

You might want to try to search by id, as this is unique for an element.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.