Nikita Kozlovsky
Nikita Kozlovsky

Reputation: 85

Selenium Web Driver FindElement() method doesnt work(NoSuchElementException)

So my problem is simple. This is my code:

    driver.findElement(By.id("j_username")).sendKeys("nk");
    driver.switchTo().frame(0);
    driver.findElement(By.id("j_password")).sendKeys("1");

First findElement() method works correctly, but when im trying to use it in second time im getting this error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"j_password"}

All ids are correct.

Upvotes: 1

Views: 139

Answers (1)

Andrei
Andrei

Reputation: 5637

Try this:

driver.findElement(By.id("j_username")).sendKeys("nk");
driver.findElement(By.name("j_password")).sendKeys("1"); // find by name

second element doesn't have id, at least in the HTML you have provided.

Upvotes: 2

Related Questions