-1

I have a webpage which i'm trying to automate using selenium webdriver...will give a short description abt d webpage, when i enter a valid id in the inputbox and clicks on search button..i will get the results of the input provided...if i give an invalid input..it will give "No records Found!" message..i want to handle both the cases by writing isElementPresent(By by) method...can anyone help on this ?? how to write a method including syntax...or anyone please post the sample method with a code example...sooner response is much appreciated !!

1 Answers1

1

I put together a code snippet in another question very recently that does this:

https://stackoverflow.com/a/29149283/4611801

public boolean elementExists(By selector)
{
    try
    {
        driver.findElement(selector)
        return true;
    }
    catch(NoSuchElementException e)
    {
        return false;
    }
}
Community
  • 1
  • 1
aholt
  • 2,829
  • 2
  • 10
  • 13