0

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 )

enter image description here

4
  • 1
    can't find - xpath/css_selector for which WebElement/field ? Commented Jan 3, 2018 at 9:13
  • 1
    What do you want to do? Commented Jan 3, 2018 at 9:13
  • click on the checkbox in the page Commented Jan 3, 2018 at 9:24
  • here try this github.com/matty120/I-m-Not-A-Robot-Clicker Commented Jan 3, 2018 at 9:32

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

7 Comments

seconde, can you explain me how u found it?
when i inspect using chrome it takes me to the element and then i used classname of it. I am able to do it.
yea but how you know that you have to change frame and the name of the frame?
i understand how you find the class name but not how you knew that you need to switch frame and what is the name of the frame
when i tried with class name , i got element not found exception. later i checked, inside frame or not. then i used switch to element. if element is not found then, mainly two reasons. 1. we are not giving correct locator or element is not on the page 2. it may be inside the iframe.
|
0

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.

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.