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?
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. :\

INPUTthat you are trying to click in your code (id=recaptcha-token) is hidden so Selenium won't interact with it by design.recaptcha-anchorwas the targeted value.