Home > Software engineering >  How can I click on the text ? I have only class in this in selenium with java
How can I click on the text ? I have only class in this in selenium with java

Time:10-01

HTML

<div class="login pull-left ml-22" onclick="ShowLoginPopup();">Sign in</div>

Selenium-Java

Thread.sleep(2000);
driver.findElement(By.xpath("//div[text()='sign in']")).click();

How do I open this

CodePudding user response:

Your xpath is wrong.

You are using

//div[text()='sign in']

but it should be

//div[text()='Sign in']

Note that character in xpath are case sensitive.

The HTML is a part of Angular website, Please induce explicit waits

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[text()='Sign in']"))).click();
  • Related