java - StaleElementReferenceException even when I use `FluentWait` -
java - StaleElementReferenceException even when I use `FluentWait<>` -
i run web e2e tests (using cucumber, junit, selenium webdriver) on ubunto.
my test fails sporadically when using remotewebdriver (never fails local-webdriver)
then banner image in preview html should "p_1047_o_9075_banner_1423040308.png" failure org.openqa.selenium.staleelementreferenceexception: stale element reference: element not attached page document
i thought have bypassed exception when refactored code this:
public string getsrcafterwait(final by) { webelement webelement = getelementafterwaitfordisplay2(by); string currentsrc = null; if (webelement != null) { currentsrc = webelement.getattribute("src"); } homecoming currentsrc; } public webelement getelementafterwaitfordisplay2(final by) { wait<webdriver> wait = new fluentwait<>(driver) .withtimeout(30, timeunit.seconds) .pollingevery(5, timeunit.seconds) .ignoring(nosuchelementexception.class, staleelementreferenceexception.class); homecoming wait.until(expectedconditions.presenceofelementlocated(by)); }
how can stabilize test further?
update
i'm trying mentallurg
solution. structured?
public string getbuttontextafterwait(final by) { string currenttext; seek { currenttext = trytogettext(by); } grab (staleelementreferenceexception ex) { currenttext = trytogettext(by); } homecoming currenttext; }
if page dynamic, next can happen.
scenario 1. in method "getsrcafterwait", located element "getelementafterwaitfordisplay2". before phone call webelement.getattribute("src"), element changes on page. , when phone call webelement.getattribute("src"), "webelement" points obsolete (not more existing) element. leads staleelementreferenceexception.
scenario 2. may have kind of animation. periodically new instance of element create many times. "getelementafterwaitfordisplay2" find element "by" condition, time time newer object on page. after located element , before phone call webelement.getattribute("src") there new instance created on page (in dom). located variable refers obsolete instance.
the simple solution in both cases: grab exception , locate object again.
more complex solution, more generic: utilize proxy objects , implement exception handling , locating there.
java google-chrome selenium selenium-webdriver webdriver
Comments
Post a Comment