YasserKhalil
YasserKhalil

Reputation: 9568

Get XPath for element

I am trying to use selenium and I couldn't get the XPath of an element although I inspected the element and copy the XPath This is the URL of the website https://www.moj.gov.kw/AR/pages/eservices01.aspx The element is the square next to "I'm not a robot" and this is my try that didn't work

bot.FindElementByXPath("//*[@id='recaptcha-anchor']").Click

Upvotes: 0

Views: 249

Answers (2)

YourHelper
YourHelper

Reputation: 735

i have tested this and it works :

import this classes first:

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

this code will click the button

 new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name, 'a-') and starts-with(@src, 'https://www.google.com/recaptcha')]")));
 new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='recaptcha-checkbox-border']"))).click();

Upvotes: 2

Rafael Carvalho
Rafael Carvalho

Reputation: 30

Did you checked inside the DOM if this captcha is inside an iframe? If so you'll need to switch to this frame first.

Upvotes: 1

Related Questions