简体   繁体   中英

How to wait for progress bar using Web Driver in java

Action: if i click any link , progress bar was displayed once page loaded completely then that progress bar was hided

Doubts: we want to automate the above action, how can i check the progress action complete or not

below are the html code

once i click the link html looks like this

<div id ="divProgress" class="progresswindow" style="display: block;"></div>

then page loading completed html looks like this

<div id ="divProgress" class="progresswindow" style="display: none;"></div>

so how can i check this progress bar completed or not, currently i'm using Thread.sleep(), but some time web driver raise the exception

Other element would receive the click: <div id="divProgress" class="progresswindow" style="display: block;">...</div>

Please provide an suggestion how this handle with Explicit wait

Rather than Thread.sleep() to wait for any condition, you should be using the WebDriverWait and ExpectedConditions classes.

In your case, you should wait until the div with the progress bar becomes invisible:

    long timeoutInSeconds = 30;
    new WebDriverWait(driver, timeoutInSeconds)
  .until(ExpectedConditions.invisibilityOfElementLocated(By.id("divProgress")));

As you've found, Thread.sleep() is too brittle to be used safely in test code - you should always be waiting for something you can check for. As a bonus your tests will probably execute a lot faster!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM