How to check the username is valid

Actually i tried to check the username and password is correct in the login page.
So i written code about to login  .Checking whether the user is valid when the log out button is visible.

But my statement is not working


driver.findElement(By.id("username")).sendKeys(sUsername);
driver.findElement(By.id("password")).sendKeys(sPassword);
boolean logvisibile = driver.findElement(By.xpath(".//*[@id='account']/ul/li[2]/a")).isDisplayed();

driver.findElement(By.name("login")).click();

Thread.sleep(1000);

if(logvisibile == true)

{
System.out.println("Succesfull");

}else

{
System.out.println("Failed");

}
}

Out put:
FAILED: test(“testuser_1″, “Test@123″)
org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’account’]/ul/li[2]/a”}
Command duration or timeout: 10.06 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

vinu Default Asked on March 18, 2015 in Selenium WebDriver.

Hi Venu,Your question and code is not matching, please check once again.Q1: Check the username and password is correct in the login page. A: Code is present.Q2: Checking whether the user is valid when the log out button is visible. A: Where is the code for logout? and validating the user.Make sure what you are asking at-least entire scenario so any one can give the answer to your question.t Sachin

on March 22, 2015.
Add Comment
1 Answer(s)

Hi Vinu,

Instead of using isDisplayed, please use isElementPresent.

boolean logvisibile = driver.findElement(By.xpath(“.//*[@id=’account’]/ul/li[2]/a”)).isElementPresent();

yashraj Train Answered on March 18, 2015.

Thanks for helping..

But only

  • isDisplayed()
  • isSelected()
  • isEnabled()

is there is Testng..what will do

Thanks in advance

on March 18, 2015.
Add Comment

Your Answer

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