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();
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With