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