8

I have scenario to click hyperlink, and will open new tab (active window will move to new tab after click hyperlink)

When i try to move to webdriver to new tab using switchTo() method, then followed by WebDriverWait.until browser automatically close with error

org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
from no such execution context
  (Session info: chrome=73.0.3683.103)

I use System.out.println(driver.getWindowHandle()) and i can see driver moving to new tab.

How i can fix above error? I have try using Iterator for loop into windowHandle

Seems can't use WebDriverWait.until(ExpectedConditions) to wait for new tab. Always getting an error cannot determine loading status from no such execution context

Weird thing, I can use Thread.sleep(1000).

How i can avoid using Thread.sleep in this case? Because implicit wait can't work too

Working code with Thread.sleep()

public class MyCode {
    private WebDriver driver;
    private WebDriverWait wait;

    @Test
    public void openPrestaShopFromDemoWebsite() {
        System.setProperty("webdriver.chrome.driver", "chromedriver");
        ChromeOptions chromeOptions = new ChromeOptions()
                .addArguments("--start-maximized", "--incognito");

        driver = new ChromeDriver(chromeOptions);
        driver.navigate().to("http://demo.prestashop.com");
        wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loadingMessage")));

        driver.switchTo().frame("framelive");
        String parentTab = driver.getWindowHandle();
        driver.findElement(By.partialLinkText("Ecommerce software by PrestaShop")).click();

        Set<String> windowHandles = driver.getWindowHandles();
        Iterator<String> it = windowHandles.iterator();

        while (it.hasNext()) {
            String newTab = it.next();

            if (!parentTab.equals(newTab)) {
                driver.switchTo().window(newTab);

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                wait.until(ExpectedConditions.titleIs("Create and develop your business with PrestaShop"));
                driver.close();
            }
        }

        driver.switchTo().window(parentTab);
        driver.switchTo().frame("framelive");
        assertThat(driver.findElement(By.linkText("Personal info")).isDisplayed());

        driver.quit();

    }
}

Not working code (cannot determine loading status from no such execution context)

public class MyCode {
    private WebDriver driver;
    private WebDriverWait wait;
    private WebElement element;

    @Test
    public void openPrestaShopFromDemoWebsite() {
        System.setProperty("webdriver.chrome.driver", "chromedriver");
        ChromeOptions chromeOptions = new ChromeOptions()
                .addArguments("--start-maximized", "--incognito");

        driver = new ChromeDriver(chromeOptions);
        driver.navigate().to("http://demo.prestashop.com");
        wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loadingMessage")));

        driver.switchTo().frame("framelive");
        String parentTab = driver.getWindowHandle();
        driver.findElement(By.partialLinkText("Ecommerce software by PrestaShop")).click();

        Set<String> windowHandles = driver.getWindowHandles();
        Iterator<String> it = windowHandles.iterator();

        while (it.hasNext()) {
            String newTab = it.next();

            if (!parentTab.equals(newTab)) {
                driver.switchTo().window(newTab);

                wait.until(ExpectedConditions.titleIs("Create and develop your business with PrestaShop"));
                driver.close();
            }
        }

        driver.switchTo().window(parentTab);
        driver.switchTo().frame("framelive");
        assertThat(driver.findElement(By.linkText("Personal info")).isDisplayed());

        driver.quit();

    }
}
1
  • Update the question with the code block for ...click hyperlink... step Commented Apr 17, 2019 at 9:01

2 Answers 2

7

I had been running into this same problem for a few days and it seems that it is actually an issue with chromedriver. The solution that worked for me was to add the following flag/argument to your chromedriver options:

--disable-site-isolation-trials

Here is the chromedriver issue (and solution) I'm referring to.

If the flag does not work, you may also try upgrading to chromedriver v75

Sign up to request clarification or add additional context in comments.

Comments

-2

As the link is opening in a new tab, you need to switch the driver to the new tab and for that, you can use the following code:

ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));

And if you want to switch to the original tab, you need to use:

driver.switchTo().window(tabs.get(0));

2 Comments

doesn't work, after switchTo() and followed by WebDriverWait.until, webdriver return cannot determine loading status from no such execution context
@J.Doem Can you add the code which you have used after switching the tab ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.