java - How to execute else if(xpathcondition) , If first xpathcondition fails? -



java - How to execute else if(xpathcondition) , If first xpathcondition fails? -

if(driver.findelement(by.xpath("//div/h3[contains(text(),'movenpick hotel deira')]")).isdisplayed()) { } else if(driver.findelement(by.xpath("//div/h3[contains(text(),'hotel inn')]")).isdisplayed()) { }

in above code, if status fails means how execute else if(xpathcondition), failed status showing exception "element not found". if handled exception, how execute else if?? advance help !!

ideally isdisplayed() should homecoming false instead of throwing exception.

you can go saifur answer. approach (as per this)

try { if(driver.findelement(by.xpath("//div/h3[contains(text(),'movenpick hotel deira')]")).isdisplayed()) { } }catch(){ //catch executes else part when exception thrown. if(driver.findelement(by.xpath("//div/h3[contains(text(),'hotel inn')]")).isdisplayed()) { } }

check issue well

java selenium xpath selenium-webdriver

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -