Erin Erin - 1 year ago 70
Java Question

Program terminates entering pass into textbox with webrunner

public static void main(String[] args) {

System.setProperty("", "C://chromedriver//chromedriver.exe");
WebDriver driver = new ChromeDriver();

//Maximize the Browser window


WebElement signin = driver.findElement("gb_70"));;

WebElement username = driver.findElement("Email"));

WebElement next = driver.findElement("next"));;

WebElement password = driver.findElement("Passwd"));

WebElement next1 = driver.findElement("signIn"));;

My program terminates when it gets to the password entry screen.. it says

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"Passwd"}
(Session info: chrome=53.0.2785.143)

However, I have tried ID element and Xpath element and they are both correct


Answer Source

Possibly you need to wait after; command. After clicking next button, your input filed is not loaded yet. So, wait for the element to get loaded and put text in it.


You can use explicit wait for this. It's better way then Thread.sleep(). Specify a maximum time to wait for element. If the specified time elapsed before your element is visible then it will throw a exception.

Code snippet:

WebDriverWait wait = new WebDriverWait(driver, 30); // waiting for maxiumum of 30 seconds

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download