5

I'm testing my app with tumblr and I have to log in and out as I go through procedures. While doing so, I'm having trouble clicking a checkbox that keeps popping up. How can I use selenium-webriver in python to click it?

I've tried selecting xpaths, ...by_ids, and by_classes, they won't work, so now I'm trying to use the mouse's coordinates to physically click the item. (This is on the tumblr login page, fyi)

enter image description here

Above is the html of the item I'm trying to select.

(EDIT:) I've the following selectors:

#checkbox = driver.find_element_by_id("recaptcha-anchor")
#checkbox = driver.find_element_by_id("g-recaptcha") 
#driver.find_element_by_xpath("//*[@id='recaptcha-token']")
#driver.find_element_by_css_selector("#recaptcha-anchor")
#driver.find_element_by_xpath("//*[@id='recaptcha-anchor']")
#driver.find_element_by_id("recaptcha-token").click()
#driver.find_element_by_class_name('rc-anchor-center-container')
#checkbox = driver.find_element_by_id("recaptcha-anchor")
5
  • Can you provide the exact url? I cannot see the checkox on log in page? Plus, provide the exact css/xpath you tried to see if there is any bug in them Commented Sep 7, 2015 at 21:23
  • tumblr.com/login is the exact url, they checkbox will appear when when you have logged in and out a couple times via tumblr. @Saifur Commented Sep 7, 2015 at 21:55
  • Cannot reproduce. tried at least 5 times Commented Sep 7, 2015 at 22:03
  • The attributes mention recaptcha... is this some bot prevention dialog? Commented Sep 8, 2015 at 0:50
  • Its the captcha checkbox thingy, I'm trying to click it @JeffC Commented Sep 8, 2015 at 2:09

4 Answers 4

7

Seems you can’t use a selector directly. Instead select an element before the reCaptcha, then use send_keys to tab to the checkbox, and space to tick it. See final line of code below for example.

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

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#modify line below to location of your chromedriver executable
chrome_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 bar
password.send_keys(Keys.TAB + Keys.TAB + " ")
Sign up to request clarification or add additional context in comments.

Comments

0

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');")

7 Comments

when I use this code, it'll just click it or something?
It should check the checkbox. And, I assumed it would work without knowing the dom structure
i tried a wait 10 seconds and then your code, but still got an error
I really need to see what's happening on the page. It's hard to pinpoint the issue without knowing the actual cause
can we go into a chat?
|
0

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

Comments

-3

Here is a simple example that works for me in Java:

driver.findElement(By.id("checkbox_id")).click();

In Python, it seems to be:

driver.find_element_by_id("checkbox_id").click()

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.