Selenium boolean condition not working -


i write code have found result element visible or not.but unfortunately ,

i have received exception.

org.openqa.selenium.nosuchelementexception: no such element: unable locate element: {"method":"xpath","selector":".//*[@class='airbnb-wide-block-search-btn js-airbnb-search-btn']"}

here code

wd.navigate().refresh(); thread.sleep(7000); boolean airbnb = wd.findelement(by.xpath(".//*[@class='airbnb-wide-block-search-btn js-airbnb-search-btn']")).isdisplayed(); assertfalse(airbnb, "airbnb add not show after clicking add 1 times"); } 

is there suggestion why element not found showing..if element not found should false not sure mistake?

to avoid exception, , expensive use of try - catch, can locate element using findelements. if result list not empty can check if existed element displayed or not

list<webelement> elements = wd.findelements(by.xpath(".//*[@class='airbnb-wide-block-search-btn js-airbnb-search-btn']")); assertfalse(elements.size() > 0 && elements.get(0).isdisplayed(), "airbnb add not show after clicking add 1 times"); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -