java - Getting stale element reference: element is not attached to the page document exception -
in application, when open page,left hand side displayed list of tabs.
by default,one tab opened status , other tabs closed status,so looking find opened status tab class name , clicked tab, has closed,then had give tab id open.
while executing code,i getting "stale element reference: element not attached page document" exception.
i have tried implicit wait option well.
could 1 please on issue resolve?
driver.manage().timeouts().implicitlywait(1000,timeunit.seconds); webelement element5 = driver.findelement(by.classname("topitemactive")); if(element5.isenabled()) { element5.click(); } driver.manage().timeouts().implicitlywait(2000,timeunit.seconds); webelement element6 = driver.findelement(by.id("id_16_cell")); element6.click(); system.out.println("tab opened");
my guess tabs created , removed javascript. webdriver download webpage , store in instance. if changed due javascript webdriver isnt aware of it.
this work simple solution
webdriverwait wait = new webdriverwait(driver, 10); wait.until(expectedconditions.refreshed(expectedconditions.elementtobeclickable(by)));
what have found there isnt it. catch exception thrown , try again. created new function "click"
public string click(by by){ string text = ""; driver.manage().timeouts().implicitlywait( 5, timeunit.seconds ); boolean unfound = true; int tries = 0; while ( unfound && tries < 3 ) { tries += 1; try { wait.until(expectedconditions.refreshed(expectedconditions.visibilityofelementlocated(by))); text = driver.findelement(by).click(); unfound = false; logger.info("click element "+stripby(by)); } catch ( staleelementreferenceexception ser ) { logger.error( "error: stale element exception. " + stripby(by) ); } catch ( nosuchelementexception nse ) { logger.error( "error: no such element exception. " + stripby(by)+"\nerror: "+nse ); } catch ( exception e ) { logger.error( e.getmessage() ); } } if(unfound) assert.asserttrue(false,"failed locate element locator " + stripby(by)); return text;
}
Comments
Post a Comment