0

I am simulating website with 3G capability using selenium 4 and page load from one to another takes more than 60 seconds which is default timeout. I am overriding it with page load timeout to 120 seconds. But am getting exception org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died error.

So, by this it means it's not taking more than 60 seconds to quit the browser under test.

Even giving explicit wait not helping since its not moving forward with the next line of code in class.

Script has executed till Sign in line of code. Issue happens when page is navigating just on the line of explicit wait

    System.setProperty("webdriver.chrome.driver","/Downloads/chromedriver-2");
    ChromeDriver driver=new ChromeDriver();
    DevTools devTools = driver.getDevTools();
    devTools.createSession();
    devTools.send(Network.emulateNetworkConditions(
            false,
            20,
            4000,
            5000,
            Optional.of(ConnectionType.CELLULAR3G)
    ));
    driver.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);
    driver.get("https://www.youtube.com/feed/library");
    driver.findElement(By.xpath("//div[@id='button']//yt-formatted-string[contains(text(),'Sign in')]")).click();
    WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(120));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='email']")));
    driver.findElement(By.xpath("//input[@type='email']")).sendKeys("check");
    driver.quit();

How to make navigation between pages to have predefined wait time or how to make it come under explicit timeout defined? How to approach this to have a reliable solution? Edit: Code changed after suggesting below

enter image description here

Sriram S
  • 169
  • 14

1 Answers1

0

You are mixing Implicit and Explicit Selenium waits together.
This is highly not recommended and causes problems.
The actual behavior of waits in this case is not as you expecting.
See here, here, here and other topics dealing with this issue for detailed explanations.
Instead of

driver.findElement(By.xpath("//div[@id='button']//yt-formatted-string[contains(text(),'Sign in')]")).click();

try this:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='button']//yt-formatted-string[contains(text(),'Sign in')]"))).click();

Of cause you should put

WebDriverWait wait=new WebDriverWait(driver, Duration.ofSeconds(120));

before that line. Normally we define this immediately after instantiating the driver.
Also, instead of presenceOfElementLocated you should use visibilityOfElementLocated for email input too.
Like this:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='email']"))).sendKeys("check");
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Even when we remove either this driver.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS); or the Explicit wait , result is same. Its making no difference to the error – Sriram S Aug 15 '21 at 07:45
  • for Sign in - we don't need any wait right since its with driver.get , it will wait till the page is loaded (default timeout 60 seconds). With the code posted above, am able to click on sign in without any issues. I have just tried only explicit wait now with no implicit wait as suggested by you. Still seeing the same error – Sriram S Aug 15 '21 at 08:15
  • Added image in the question . Issue is after sign in button which is clicked . Its navigating to gmail page but timing out after 60 seconds since page is not loaded completely – Sriram S Aug 15 '21 at 08:45
  • Maybe it would be better to remove `driver.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);` command? – Prophet Aug 15 '21 at 10:35
  • Yes, I did that. Just have explicit wait defined now. Nothing else. But still same error occurs – Sriram S Aug 15 '21 at 12:27