Reputation: 109
Somebody can upload code of clicking the checkbox in this page IN PYTHON ONLY- https://www.google.com/recaptcha/api2/demo
i cant find the xpath for this code ...
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
driver1 = webdriver.Firefox()
driver1.get("https://www.google.com/recaptcha/api2/demo")
driver1.find_element_by_xpath(...).click()
if it wasn't clear, i want to click this button ( in the circle )
Upvotes: 0
Views: 1886
Reputation: 101
Switching to iFrames catches a lot of people out, but if you have content that is loaded from a different domain (in this case the Captcha) then you need to switch to that with
driver.switchTo().frame(<integer of frame or id>);
Then you will be be able to interact the selector of your choice.
Upvotes: 0
Reputation: 5347
The xpath is //*[@class="recaptcha-checkbox-checkmark"]
The checkbox is inside iframe first you need to switch to the frame then you can find element and click.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
driver1 = webdriver.Firefox()
driver1.get("https://www.google.com/recaptcha/api2/demo")
driver1.switch_to.frame(driver.find_element_by_css_selector('iframe'))
driver1.find_element_by_xpath('//*[@class="recaptcha-checkbox-checkmark"]').click()
I have tried with java and it is able to click on the checkbox, the java code is given below.
driver=new FirefoxDriver();
driver.get("https://www.google.com/recaptcha/api2/demo");
driver.switchTo().frame(0);
new WebDriverWait(driver, 120).until(ExpectedConditions.visibilityOf(driver.findElement(By.className("recaptcha-checkbox-checkmark")))).click();
Upvotes: 2