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
Post a Comment