Selenium (Java) - Keep clicking a button until specific text is present in an element and fail if certain amount of time is exceeded -


i have scenario can stop engine clicking button starts background process , can see current status of engine every time after clicking refresh status button in page. issue time varies engine stop 30 seconds 2 mins depending upon load on server. don't want write while loop thread.sleep() it's bad idea , unnecessarily increase test time in selenium. there intuitive way wait 20 seconds every time , click refresh status button until offline text present in element , have timeout of 3 mins whole process?

you can extend expectedconditions class , override static method texttobepresentinelementlocated if see implementation pretty simple:

public static expectedcondition<boolean> texttobepresentinelementlocated(       final locator, final string text) {      return new expectedcondition<boolean>() {       @override       public boolean apply(webdriver driver) {         try {           string elementtext = findelement(locator, driver).gettext();           return elementtext.contains(text);         } catch (staleelementreferenceexception e) {           return null;         }       }        @override       public string tostring() {         return string.format("text ('%s') present in element found %s",             text, locator);       }     };   } 

just add element.click() in method proper place , use class extended class in webdriverwait


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -