I need selenium to check a box, but I can't check it. When I input the Xpath, it just clicks the hyperlink in the text (as seen in image 2). Some background, I code my script in Selenium Python, I am new to coding.
I don't know what the element of the checkbox itself is called, but I figured the checkbox is the purple line that says "::before". I feel like I've tried every possible way to code this.
If more information is needed, just ask.
Try this
driver.find_element_by_xpath(".//input[@id='denmark.agreeToTerms']").click()
You didn't show what locator are you using.
Anyway, I guess the correct locator of the checkbox is the following XPath
//input[@id='denmark.agreeToTerms']
if you prefer css_selector
-
input#denmark.agreeToTerms
driver.find_element_by_xpath("//label[@for='denmark.agreeToTerms']").click()
For checkboxes click the label tag.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.