"No element is found" exception in WebDriver running on Internet Explorer using Java
we want to move our tests to selenium 2 and i have found an issue which i don't know how to resolve it.
I am using the following commands for webdriver:
WebDriver driver = new InternetExplorerDriver();
driver.navigate().to("webapp");
Thread.sleep(3000);
System.out.println(driver.getPageSource());
WebElement element = driver.findEl开发者_运维知识库ement(By.id("someid"));
At the last line exception is raised and no element is found. The same example works well in firefox, but we need it to have it in IE. I have tried to add more sleep, but it doesn't help. getPageSource method returns correct html.
I have also tried to get body tag, with the following command, but it returns null.
List<WebElement> list = driver.findElements(By.tagName("body"));
Our web application is created in gwt.
Do you know what may cause that selenium doesn't see any element?
The code you posted is absolutely problem-free.
Make sure you use some of the newer Selenium versions and not some old alpha/beta version. Which IE do you use, does it have any special add-ons? Does it work with some minimal web pages like this?
<html>
<input id='myId' />
</html>
Have you tried searching for another element? By some other technique like xpath or css selector? Is your capitalization absolutely right? If you save the html of the page and try it loading locally with said testcase, does it work? Could you provide a minimal test case? As a unlikely-to-work last resort solution, you can try to fallback to Selenium 1 for two lines of code that help waiting in some rare cases:
Selenium sele = new WebDriverBackedSelenium(driver, "webapp");
sele.waitForPageToLoad("10000");
Try using a smart wait like this before making your assignment statement. You just need to pass in your current WebDriver object and a timeout value.
new WebDriverWait(driver, timeOutInSeconds).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(final WebDriver theDriver) {
return Boolean.valueOf(theDriver.findElements(By.id(elementId)).size() > 0);
}
});
maybe you can try to add
driver.switchTo().window(driver.getWindowHandle());
before searching for elements. I had this issue when Webdriver moved between pages on different servers (not with IE but with Firefox).
精彩评论