0

I'm writing a script for an application. The requirement is to click on Login button in the first page, and when it goes to the login page, I have to click on Google login button. The button has this attribute data-testid, which is set to google-login. So I tried to locate the button as below:

WebElement googleLoginBtn = driver.findElement(By.xpath("//button[@data-testid='google-login']"));

But the test is failing with the below error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@data-testid='google-login']"}

I was able to locate the login button in the same way. It is working fine. Even I tried to target the element in the browser DevTools using the above XPath expression, which locates the button correctly. But I don't know why Selenium is unable to locate it. Could anyone suggest a solution to this?

  • You probably missing a delay. Please share all your code – Prophet Aug 26 '22 at 12:59
  • Can try the answers given in the post below: https://stackoverflow.com/questions/19536954/what-is-the-best-way-to-avoid-nosuchelementexception-in-selenium – ravi kumar Sep 05 '22 at 12:22

0 Answers0