2

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?

enter image description here

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import sys
import smtplib

email = "[email protected]"
pswd = "xxxxx"

driver = webdriver.Firefox()
actions = ActionChains(driver)


driver.get("https://www.tumblr.com/login")
driver.find_element_by_id("signup_email").send_keys(email)
driver.find_element_by_id("signup_password").send_keys(pswd)
driver.find_element_by_id("signup_forms_submit").click()


#wait = WebDriverWait(driver, 5)


time.sleep(5)


try:
    #checkbox = driver.find_element_by_id("recaptcha-anchor")
    #checkbox = driver.find_element_by_id("g-recaptcha")
    #checkbox.click()
    box = driver.find_element_by_xpath("//*[@id='recaptcha-token']")
    #box = driver.find_element_by_css_selector("#recaptcha-anchor")
    print(box.location, box.size)
    box.click()
    #actions.move_to_element(box)
    actions.click(box)
    #actions.perform()
except NoSuchElementException as e:
    print(e)
    pass

(EDIT) My error reads:

Traceback (most recent call last): File "tumblrtest.py", line 49, in <module> EC.element_to_be_clickable((By.ID, "recaptcha-anchor")) File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 76, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Stacktrace: at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/13/1rh6kf9x2k11pyfg6zsnfmg40000gn/T/tmpvkFkz_/extensions/[email protected]/components/driver-component.js:10667) at FirefoxDriver.prototype.findElement (file:///var/folders/13/1rh6kf9x2k11pyfg6zsnfmg40000gn/T/tmpvkFkz_/extensions/[email protected]/components/driver-component.js:10676) at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/13/1rh6kf9x2k11pyfg6zsnfmg40000gn/T/tmpvkFkz_/extensions/[email protected]/components/command-processor.js:12643) at DelayedCommand.prototype.executeInternal_ (file:///var/folders/13/1rh6kf9x2k11pyfg6zsnfmg40000gn/T/tmpvkFkz_/extensions/[email protected]/components/command-processor.js:12648) at DelayedCommand.prototype.execute/< (file:///var/folders/13/1rh6kf9x2k11pyfg6zsnfmg40000gn/T/tmpvkFkz_/extensions/[email protected]/components/command-processor.js:12590)

This was my error in Chrome: Traceback (most recent call last): File "tumblrtest.py", line 49, in <module> EC.element_to_be_clickable((By.ID, "recaptcha-anchor")) File "/Library/Python/2.7/site-packages/selenium/webdriver/support/wait.py", line 76, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

...nothing was clicked. :\

2
  • Which checkbox is the one that you are trying to click? It's not clear from your description. The INPUT that you are trying to click in your code (id=recaptcha-token) is hidden so Selenium won't interact with it by design. Commented Aug 26, 2015 at 1:33
  • @JeffC ...came to the conclusion that the recaptcha-anchor was the targeted value. Commented Aug 26, 2015 at 19:11

2 Answers 2

4

Click the recaptcha-anchor instead:

driver.find_element_by_id("recaptcha-anchor").click()

You might also need to wait for the element to be clickable before performing an action:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

recaptcha_anchor = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.ID, "recaptcha-anchor"))
)
recaptcha_anchor.click()
Sign up to request clarification or add additional context in comments.

3 Comments

@marriedjane875 what happens exactly? Are you getting any errors? Can you share the complete code you have so far (and if possible include the link to the website)? Thanks!
I added all of my code above and added the error in the edit as well. Thanks a milli :)
still haven't foud a solution to the issue yet, but I won't give up :)
0

Find recaptcha checbox with

recaptcha = self.driver.find_element_by_xpath("//*[@role='presentation']"); time.sleep(random.uniform(2, 5))

then click it

recaptcha.click(); time.sleep(random.uniform(1, 1))

This method is currently working.

1 Comment

Please add some explanation to your answer!

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.