headless browser testing

Hello, I am testing a web application using selenium html unit driver. when i am tring to find an element by using Xpath am facing some errors which i cnnot resolve. Please help me out with these errors. Exception in thread “main” org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //*[contains(@id, ‘login_’)] (tried for 3 second(s) with 500 MILLISECONDS interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:232) at basic.selenium.FirstProgram.login(FirstProgram.java:51) at basic.selenium.FirstProgram.main(FirstProgram.java:111) Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //*[contains(@id, ‘login_’)] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘unknown’, revision: ‘5234b32’, time: ‘2017-03-10 09:02:31 -0800’ System info: host: ‘DRSCOM004’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_121’ Driver info: driver.version: unknown at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:899) at java.util.Optional.orElseThrow(Unknown Source) at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:898) at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44) at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:208) at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:204) at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:654) at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:647) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209) … 2 more

 

here is my code for the two test methods login and logout of a web application

 
public void login() {

WebDriverWait wait = new WebDriverWait(driver, 3);
WebElement login = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//*[contains(@id, ‘login_’)]”)));
driver.findElement(By.xpath(“//*[contains(@id, ‘login_’)]”));
login.sendKeys(“*****”);

WebElement password = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//*[contains(@id, ‘password_’)]”)));
driver.findElement(By.xpath(“//*[contains(@id, ‘password_’)]”));
password.sendKeys(“*******”);

WebElement btnLogin = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//*[contains(@id, ‘btnLogin_’)]”)));
driver.findElement(By.xpath(“//*[contains(@id, ‘btnLogin_’)]”));
btnLogin.click();

System.out.println(“title of the page is: “+driver.getTitle());

//wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[contains(@id, ‘menu_userMenu_’)]”)));

WebElement userMenuBtn = driver.findElement(By.xpath(“//*[contains(@id, ‘menu_userMenu_’)]”));
Assert.assertNotNull(userMenuBtn, “Login was not successful”);
userMenuBtn.click();

}
public void logout() {

WebDriverWait wait = new WebDriverWait(driver, 3);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[contains(@id, ‘menuitem_logout_’)]”)));

driver.findElement(By.xpath(“//*[contains(@id, ‘menuitem_logout_’)]”)).click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//*[contains(@id, ‘btnLogin_’)]”)));

WebElement loginBtn = driver.findElement(By.xpath(“//*[contains(@id, ‘btnLogin_’)]”));
Assert.assertNotNull(loginBtn, “Logout was not successful”);

driver.quit();

}

public static void main (String[] args) {
FirstProgram obj = new FirstProgram();
obj.invokebrowser();
obj.login();
obj.logout();

}
}

 

 

thanks in advance   Regards Giri Prasad Kota

Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.