I'm getting an Exception as below ,when i run the selenium code by using a loop. It executes some steps and then display the message.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: *[name='user']
My code is:
package login;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class login {
public static void main(String[] args) {
// Web Driver configuration
System.setProperty("webdriver.gecko.driver", "E:\\Software\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver ();
String baseURL = "http://10.10.80.11/";
driver.get(baseURL);
// Login_logout Process
for (int i=1;i<=100;i++){
WebElement element = driver.findElement(By.name("user"));
// Enter user id
element.sendKeys("abc");
WebElement element1 = driver.findElement(By.name("password"));
// Enter user id
element1.sendKeys("abc");
driver.findElement(By.id("button-1013-btnEl")).click(); //Submit button
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.findElement(By.id("button-1021-btnEl")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String expectedURL = "http://10.10.80.11/";
String actualURL;
actualURL = driver.getCurrentUrl();
//compare the actual URL of the page with the expected one and print
if (actualURL.contentEquals(expectedURL)){
System.out.println(+i);
}
else {
System.out.println("Test Fail!");
}
}
}
}