No Element exception thrown in WebDriver running in Internet Explorer using Java

we want to transfer our tests to selenium 2, and I found a problem that I don’t know how to solve.

I use the following commands for webdriver:

WebDriver driver = new InternetExplorerDriver(); driver.navigate().to("webapp"); Thread.sleep(3000); System.out.println(driver.getPageSource()); WebElement element = driver.findElement(By.id("someid")); 

An exception is thrown on the last line and the item was not found. The same example works well in firefox, but we need it to be in IE. I tried to add more sleep, but that will not help. The getPageSource method returns the correct html.

I also tried to get the 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 can lead to the fact that selenium does not see any element?

+6
source share
3 answers

The code you posted is absolutely no problem.

Make sure you are using some of the newer versions of Selenium, and not some old alpha / beta version. Which IE are you using, 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 to find another item? By any other method like xpath or css selector? Is your capitalization right? If you save the html pages and try downloading locally with a test test, will this work? Could you provide a minimum test? As an unlikely solution for the last resort, you can try backtracking to Selenium 1 for two lines of code that help wait in some rare cases:

 Selenium sele = new WebDriverBackedSelenium(driver, "webapp"); sele.waitForPageToLoad("10000"); 
+1
source

Try using an intelligent wait like this before you make your assignment statement. You just need to pass the current WebDriver object and the 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); } }); 
+1
source

maybe you can try adding

 driver.switchTo().window(driver.getWindowHandle()); 

before searching for items. I had this problem when Webdriver moved between pages on different servers (not with IE, but with Firefox).

0
source

Source: https://habr.com/ru/post/892037/


All Articles