简体   繁体   中英

How can I click on this check box using Selenium Python?

I can click all of the other checkboxes on the page. But when it comes to this one, it won't allow me to click on it

The HTML code for the checkbox is:

<input id="ContentPlaceHolder1_wucSignInStep2_chkTC" type="checkbox" name="ctl00$ContentPlaceHolder1$wucSignInStep2$chkTC">

My code for clicking the text box:

element = driver.find_element_by_xpath('//span[span/input[@name="checkbox checkbox-primary"]]').click()

I can provide the full code if required.

There is an id associated with your input field! You can use the id to find the element

element = driver.find_element_by_id('ContentPlaceHolder1_wucSignInStep2_chkTC').click()

That should do it.

If you are getting an element not visible error then you can try the following:

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_id("ContentPlaceHolder1_wucSignInStep2_chkTC")

actions = ActionChains(driver)
actions.move_to_element(element).perform()
driver.execute_script("arguments[0].click();", element)

The above code will make the element visible and also, put the mouse cursor over the checkbox.

I tried to follow this instruction, and it works for me.

https://www.toolsqa.com/selenium-webdriver/selenium-checkbox/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM