2
votes

I tell Selenium to wait until it sees an element - Selenium sees it I tell Selenium to click on this element, it is a button to link to a new page - Selenium click on it.

The problem is that after clicking it, Selenium will then wait until the next page is fully loaded (the page sometimes loads in a second, or waits for ages, I think it's a problem with Zen Desk Live Chat on that page).

When it is fully loaded it will then throw an error and say that the element it clicked on cannot be seen (naturally it can't because it is now on a new page)

I have tried changing the wait time with

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

however this doesn't help. I have also tried

wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(element)));

However this has the same problem.

Below is the code I am currently using.

try {
    wait.until(ExpectedConditions.visibilityOfElementLocated(
    By.xpath(element)));
    WebElement we = driver.findElement(By.xpath(element));
    we.click();
    System.out.println("Clicked: " + element);
}catch (Exception e){
    System.out.println(e.getMessage()); 
}   

I expect that once the element has been clicked on, that Selenium just carries on without caring if the next page has loaded up or not.

However what happens is when the 2nd page loads up, sometimes the page gets stuck "waiting for widget-mediator.zopim.com" and Selenium will not progress past the click() line until the the WebDriverWait time has expired (60 seconds) After the 60 seconds has expired I see this error in the Console Output:

[1561374309.111][SEVERE]: Timed out receiving message from renderer: 60.000
[1561374309.112][SEVERE]: Timed out receiving message from renderer: -0.002

Is something else happening here? Or does Click() wait until the page has loaded, if that click takes it to a new page? If it does is there a way to tell it to stop waiting? I have other code to check if the page has loaded or not, but I don't need Click() to do this.

Thanks in advance.

1

1 Answers

2
votes

Selenium’s (or more correctly, WebDriver’s) behavior on click is governed by the W3C WebDriver Specification. In that document, the full algorithm is defined for what happens when an element click is requested. In general, if the click will navigate to a new page, the driver will wait for that new page to be “loaded” (scare quotes intentional) according to the page load strategy until the page load timeout.

The page load strategy defaults to “normal”, or waiting for the document’s readyState to be complete. If you set it to “none” in the capabilities requested during driver instantiation, the driver will not wait at all. Choosing that route would mean you would need to handle all synchronization for pages being loaded. Note there is a third page load strategy, “eager”, but at the time of this writing, not all WebDriver implementations (most notably chromedriver) support it.

You can adjust the page load timeout at runtime in your Selenium code. One approach might be to lower the timeout to a relatively low value for the duration of clicking on this particular element, then restoring it to its prior value afterward. The drawback here is that you will have to catch the timeout exception that is thrown when the page load times out before continuing.