0

My xpath:

@FindBy(xpath = ".//div[@class=\"recaptcha-checkbox-checkmark\"]")
private WebElement captchaCheckBox;

Method:

public void clickCaptchaCheckbox() {
    captchaCheckBox.click();
}

Exception:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//div[@class="recaptcha-checkbox-checkmark"]"}
  (Session info: chrome=73.0.3683.103)
  (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'}

Why element is not visible and I can't click on it?

enter image description here

0

Your xpath seems to be fine. It also seems you're trying to locate a check-box of Google reCAPTCHA. Google reCAPTCHA is integrated to the page using iFrame.

Below is your screenshot with some additional marker from me.

enter image description here

So you have to switch to the iframe first. To do that examine your html structure and switch to the required iFrame before you're trying to interact with the item.

For details see this post: How to locate an element which is inside the iframe?

  • many thanks for advice. I have tried to switch to iframe and I noticed, that a frame name is dynamic and updates each time when a run a test. May be it is necessary to use a script in that case? – Pablo Apr 18 at 19:36
  • You do not actually need id or name for switching to frame. You can locate a frame like you do with just a regular WebElement and then swith to that. See this post: stackoverflow.com/a/35671072/8343843 – Alexey R. Apr 19 at 9:31
  • 1
    Done! Alexey, many thanks for the help and efforts – Pablo Apr 19 at 12:03
0

Copy Paste has added escape chars (\").

Change it to:

@FindBy(xpath = ".//div[@class='recaptcha-checkbox-checkmark']");
0

You should bypass recaptcha during development (and testing). The intention with using CAPTCHA is to avoid automation.

Automation and bypassing Google No CAPTCHA reCAPTCHA

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.