I am using Java Gradle, Selenium 3.8.0 and IEWebDriver 3.8.0.
Chrome and Firefox are working fine, but IE throws a org.openqa.selenium.TimeoutException: Expected condition failed
Exception, although IE also works fine, if I debug my source code step by step.
Therefore I debuged a long time to find that problem and I noticed that IE looses the connection between WebDriver and Source Code, whenever a webDriver.get(..)
is called, whichs looks like that:
driver.get(url);
waitForPageLoaded(driver);
Because of that I assume that there are some timing issues, but I already tried to handle this:
public void waitForPageLoaded(WebDriver driver) {
logger.debug("Wait until the page was loaded.");
// IE seems to fail here.
new WebDriverWait(driver, SeleniumConfigurator.TIME_OUT)
.until(d -> ((JavascriptExecutor)d).executeScript("return document.readyState")
.equals("complete"));
}
Then I noticed that IE needs some more configuration settings, but I am not allowed to setup some of them: IT restrictions -> I cannot change regedit entries.
BUT, why does it work fine, while debugging?
This is my IE setup:
case IE:
path = "../../../../../../resources/driver/win/IEDriverServer_32_v3-8-0.exe";
url = getClass().getResource(path);
if (url == null) {
logger.error("Could not find the Internet Explorer web driver binary at " + path + " ." +
"All test for this browser will be ignored.");
currentBrowserType = BrowserType.UNDEFINED;
break;
}
try {
System.setProperty("webdriver.ie.driver", Paths.get(url.toURI()).toFile().getAbsolutePath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
// https://sqa.stackexchange.com/questions/13077/unable-to-run-selenium-webdriver-script-in-ie11
InternetExplorerOptions optionsIE = new InternetExplorerOptions();
optionsIE.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
optionsIE.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
optionsIE.withAttachTimeout(SeleniumConfigurator.TIME_OUT, TimeUnit.SECONDS);
//optionsIE.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
webDriver = new InternetExplorerDriver(optionsIE);
currentBrowserType = BrowserType.IE;
break;
I have no idea what's going wrong here..
The first test works fine, after that the timeout exception appears (take a look at the comment):
@Test
public void test_Contact() {
Init();
util.logTestStart("Test contact on index page..");
String xPath = "//*[@id='contact-link']/a";
WebElement element = webDriver.findElement(By.xpath(xPath));
Assert.assertEquals(element.getAttribute("href"), "mailto:what@ever.com");
}
@Test
public void test_LegalInformation() {
Init();
util.logTestStart("Test legal information on index page..");
String xPath = "//*[@id='link-highlighted']/a";
util.aTagClickByXPath(webDriver, xPath);
Assert.assertEquals(webDriver.getCurrentUrl(), "http://whatever.com/");
}
private void Init() {
if (configurator == null) {
configurator = SeleniumConfigurator.getInstance();
}
if (webDriver != configurator.getWebDriver()) {
webDriver = configurator.getWebDriver();
}
if (util == null) {
util = new SeleniumTestUtil();
}
// Open localhost as default
util.goTo(webDriver, "http://localhost:8080/de/index");
}
public void aTagClickByXPath(WebDriver driver, String xPath) {
logger.debug("Performing a click on an a-Tag, xPath: " + xPath);
WebElement element = driver.findElement(By.xpath(xPath));
element.click(); // First click works, second one fails, cause of Timeout Exception
waitForPageLoaded(driver);
}
Does anyone have a hint?
EDIT:
org.openqa.selenium.NoSuchWindowException: Unable to get browser
get thrown for now. Timeout Exception didnt appears anymore. I changed nothing.
EDIT2:
Further information:
Node:
<div class="col-xs-12" id="link-container">
<div id="bike-link" class="pull-right">
<a href="http://whatever.com/?lang=D">
whatever
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>
<div id="link-highlighted" class="pull-right">
<a href="http://whatever2.com/"> <!-- this one -->
Rechtliche Hinweise
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>
<div id="contact-link" class="pull-right">
<a href="mailto:what@ever.com">
Kontakt
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>
</div>
Timeout definition:
public static final int TIME_OUT = 15;