Can someone help me fixing NoSuchElementException
. Let me explain what I am trying to do.
I am trying to login into an application with multiple sets of data. Lets say,
1) Valid username and password.
2) Valid username and invalid password.
Now what's happening is, I am trying to find element is present or not.
In my first case, element is present as user successfully loggedIn. But in my second case, user is not logged in and i am trying to find element present inside application after login.
Can any one tell me how to find a solution for such situation ?
wd.findElement(By.id("username")).sendKeys(UserName);
wd.findElement(By.id("password")).sendKeys(Password);
webElement.sendKeys(Keys.ENTER);
try
{
Boolean ispresent = wd.findElement(By.xpath("//div[@id='service_panel']")).isDisplayed();
if(ispresent)
{
//doing something.
}
}
catch(Exception e)
{
e.printStackTrace();
}