java - ExplicitWait taking more time if an element removed from DOM -
i'm automating this website facing issue explicitwaitconditions manage time.
scenario when click on login link or submit button after send username, shows loader during process, once process has completed loader removed dom.
i have used condition invisibilityofelementlocated below
new webdriverwait(driver, 60).until(expectedconditions.invisibilityofelementlocated(by.id("loading-bar"))); but can't predict correct time taking more time (not exectly 60 sec around 15-20 or may 30 sec.) allow execute next command.
the same line have put before 4 commands complete login process. seems consumed around 90 second login.
if not use explicitwait or remove impliciwait wait script failed time loader click instead of other element.
the code tried far :
webdriver driver = new firefoxdriver(); system.out.println("browser opened"); driver.manage().window().maximize(); driver.get("https://www.rcontacts.in"); driver.manage().timeouts().implicitlywait(30, timeunit.seconds); system.out.println("url opened"); new webdriverwait(driver, 60).until(expectedconditions.invisibilityofelementlocated(by.id("loading-bar"))); driver.findelement(by.cssselector(".ng-scope>a span[translate='login.register']")).click(); system.out.println("register link clicked"); driver.findelement(by.name("userid")).sendkeys("9422307801"); new webdriverwait(driver, 60).until(expectedconditions.invisibilityofelementlocated(by.id("loading-bar"))); driver.findelement(by.xpath("//button[@type='submit']")).click(); system.out.println("mobile number entered"); new webdriverwait(driver, 60).until(expectedconditions.invisibilityofelementlocated(by.id("loading-bar"))); is there solution loader removed start performing actions ?
or there way can wait until loader element removed dom. once removed can continue further actions ?.
according the docs,
warning: not mix implicit , explicit waits. doing can cause unpredictable wait times.
that's cause of issues. it's recommended not use implicit waits. remove them , add explicit waits needed , see how goes.
i took code , rewrote (below) , it's working every time me.
string url = "https://www.rcontacts.in"; driver.navigate().to(url); waitforloader(); driver.findelement(by.cssselector("span[translate='login.register']")).click(); waitforloader(); driver.findelement(by.cssselector("input[name='userid']")).sendkeys("9422307801"); driver.findelement(by.cssselector("button[translate='common.btns.next']")).click(); the issue having @ times many times script jumping ahead. added code waitforloader() wait loader appear (be visible) , disappear (be invisible). once did that, worked 100% of time.
public static void waitforloader() { webdriverwait wait = new webdriverwait(driver, 10); wait.until(expectedconditions.visibilityofallelementslocatedby(by.id("loading-bar"))); wait.until(expectedconditions.invisibilityofelementlocated(by.id("loading-bar"))); }
Comments
Post a Comment