Pages

Sunday 4 March 2012

How can I check the presence of WebElement on page?

We can check the presence of WebElement on page by implementing custom isElementPresent method as below:


	protected boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

This method will return true, if the WebElement with ‘by’ available otherwise returns false.

6 comments:

  1. Here is the same function converted to C#

    protected bool IsElementPresent(By by)
    {
    try
    {
    driver.FindElement(by);
    return true;
    }
    catch (NoSuchElementException)
    {
    return false;
    }
    }

    ReplyDelete
  2. My question is
    Let say your method signature is like this
    protected boolean isElementPresent(WebElement elment)

    in this case you have webelement not locator then how will you check whether element is present or not

    ReplyDelete
  3. Findelement(by By) will show an element if it is present in the DOM. This will also return true if the element is present in the DOM but hidden from the user. "Visibility" refers to present in the DOM and in the UI ( i.e. not hidden)

    ReplyDelete
  4. You have hundreds of online brokers to choose from, so we are here to help you make an informed decision. Online Stock Broker provides many resources including a comparison system based on the top brokers in the industry, Brokers Review And There Login Details to help you find the one that is best for you.

    ReplyDelete
  5. To view the real-time Fxit Stock price and to get an overview of the key fundamentals, simply visit Our Servlogin Webpage. You'll get access to revenue, earnings, valuation, predictors, and technical analysis from experts, news, historical data and Much More.

    ReplyDelete
  6. Stay In Touch With Vstr Stock? Every Move With Our Live, Real Time Stock Market Overview. Here You Will Always Be One Of The First To Know When Vstr Stock Is Increasing Or Decreasing. Our Live Information Is Delivered Right To Your Browser, Giving You All The Data You Need To Make An Informed Trading Decision. With This Information At Your Fingertips You Will Be Able To Make Quick And Educated Decisions While Keeping Track Of All The Latest Sos Stock Price Changes!

    ReplyDelete