How to use assertions for isdispalyed() method in selenium webdriver

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use assertions for isdispalyed() method in selenium webdriver

sreekumar
Hi tarun,

I want to user assertions in my projects. when i am using like below

Assert.assertTrue(driver.findElement(By.xpath("//a[@id='buttonshowmenu3333333']")).isDisplayed(),"TOC web element is not found");

Exception is throwing and test case is failed because of invalid xpath. But i want to show error message that i mentioned in the 2nd parameter in Testngresults.xml.

Please do need your help.....

Thanks
sreekumar
Reply | Threaded
Open this post in threaded view
|

Re: How to use assertions for isdispalyed() method in selenium webdriver

softwaretestingforum
Administrator
Your xPath seems ok but this solution won't work if element is not available and WebDriver will throw exception.
You may like to borrow some ideas from these threads -

http://stackoverflow.com/questions/5922930/iselementpresent-in-selenium-2-0
http://stackoverflow.com/questions/10934305/selenium-c-sharp-webdriver-how-to-detect-if-element-is-visible
~ seleniumtests.com