Confirm page load or not

I have a list of hyperlinks on one page, when I click links, they are redirected to a new tab. how to find out if the page is loaded or not. I used the do while loop to find out if the element is included or not. but I get "not such an element." could you help with this. Below is a snippet of code. I also tried with Explicit Expectation. but get the same problem.

    WebElement element7 = driver.findElement(By.id("MenuControlBNY_MenuNavBar_MenuControlBNY_MenuNavBar_p11__Tree_item_2_cell"));
    if (element7.isEnabled())
    {
        element7.click();
        System.out.println(" Report is selected");
    }

    boolean element8 = false;
    int count = 0 ;
    do
    {
        element8 = driver.findElement(By.id("working")).isEnabled();
        System.out.println("Report is loaded");
        count = count+1;
        if(count == 1000)
        {
            break;
        }
    }while(element8 == true);
+1
source share
3 answers

I use the following, its a fairly understandable explanation.

private static WebDriverWait wait = new WebDriverWait(driver, 60);
private static JavascriptExecutor js  = (JavascriptExecutor) driver;

public static void waitForPageLoaded() {
            wait.until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver driver) {
                    Boolean res = (js.executeScript("return document.readyState").equals("complete"));
                    System.out.println("[DEBUG] waitForPageLoaded: " + res);
                    return res;
            }
    });
}

EDIT: This will return true when the page is in a ready state, i.e. page loaded. Therefore, you must call the above method before looking for your element.

0

, 15

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("working")));
0

, , , , .

exict wait .

String parentWindow= driver().getWindowHandle();
element7.click();
Set<String> myset = driver().getWindowHandles();
myset.remove(parentWindow);
driver().switchTo().window((String)myset.toArray()[0]);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(locator)));
0

All Articles