Click a checkbox with selenium-webdriver Click a checkbox with selenium-webdriver selenium selenium

Click a checkbox with selenium-webdriver


I realise this is an old thread, but I couldn't find the answer anywhere else. In the end I figured it out as follows.

Note 1: this will tick the recaptcha box, but it won't solve it, you'll still need to do that manually.

Note 2: this is on macOS, so you might need a different format for chrome_path on Windows

from selenium import webdriverfrom selenium.webdriver.common.keys import Keys#modify line below to location of your chromedriver executablechrome_path = r"/Users/Username/chromedriver"driver = webdriver.Chrome(chrome_path)driver.get("https://www.btcmarkets.net/login")username = driver.find_element_by_id("userIdText")username.send_keys("Us3rn4me")password = driver.find_element_by_id("userPasswordText")password.send_keys("Pa55w0rD")#the line below tabs to the recaptcha tickbox and ticks it with the space barpassword.send_keys(Keys.TAB + Keys.TAB + " ")


Seems like this is not an input tag. So, probably manipulating the aria-checked attribute and set it to true would do it. The only way to change attribute value is JavaScriptExecutor. Try the following:

driver.execute_script("$('#recaptcha-anchor').setAttribute('aria-checked','true');")


Use code below can find the checkbox with id "recaptcha-anchor" and click it, but unable to bypass it. The following pictures will pop up.

List<WebElement> frames = driver.findElements(By.tagName("iframe"));    String winHanaleBefore = driver.getWindowHandle();    driver.switchTo().frame(0);driver.findElement(By.id("recaptcha-anchor")).click();driver.switchTo().window(winHanaleBefore);