Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find any elements in Selenium using Internet Explorer Driver

I cannot get Selenium to identify any elements with Internet Explorer Driver regardless of the page used or the selection type.

String iedriver = "C:\\selenium-server\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", iedriver);
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.xpath("//body"));

Selecting by xpath gives org.openqa.selenium.InvalidSelectorException: The xpath expression '//body' cannot be evaluated or does notresult in a WebElement. Other selection types also fail:

WebElement element = driver.findElement(By.cssSelector("body"));

or

WebElement element = driver.findElement(By.tagName("body"));

or

 WebElement element = driver.findElement(By.name("q"));

By CSS Selector, Name, or Tag Name always results in org.openqa.selenium.NoSuchElementException

All selections work perfectly fine with Firefox Driver, Chrome Driver, and even Html Unit Driver.

The browser correctly starts and the page loads as expected. driver.getCurrentUrl(); and driver.getPageSource(); return the expected values.

I tried introducing explicit and implicit waits before selecting an element but to no effect, using

Thread.sleep(10000); 

or

WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));

Also tried stepping through the code to manually wait for elements to be displayed.

Other things I tried included 1) setting the security settings to the same level in all zones 2) disabling Enhanced Protected Mode 3) setting the FEATURE_BFCACHE in the registery

I am using Selenium and IEDriverServer versions 2.41. The problem is observed running both locally and remotely. The environment is on Windows 7 64-bit using IE10 64-bit and IEDriverServer 64-bit. The same problem was observed on IE11 32-bit using IEDriverServer 32-bit. I used www.google.com here as a publicly viewable test but the problem is also observed on our internal site.

like image 331
nelziq Avatar asked May 20 '14 22:05

nelziq


People also ask

How do I search for elements in Internet Explorer browser?

Follow the below steps to locate web elements using IE Developer tool: Step #1: The primary step is to launch the IE Developer tool. Press F12 to launch the tool. The user would be able to see something like the below screen.

Does Selenium work with Internet Explorer?

Since Selenium gives the option of running our tests in multiple browsers, Selenium with IE browser blending can be used to test any application. IE has a driver, which creates a connection between Selenium WebDriver and IE. and then executes the Selenium tests on Internet Explorer.

What could be the possible reason of getting unable to locate element?

We may encounter the error - unable to locate element while working with Selenium webdriver. This leads to NoSuchElementException. This type of exception is thrown when there is no element on the page which matches with the locator value. Check if there is any syntax error in our xpath expression.

What happens when a list of elements is not found by Selenium?

selenium. NoSuchElementException occurs when WebDriver is unable to find and locate elements. Usually, this happens when tester writes incorrect element bin the findElement(By, by) method. This exception is thrown even if the element is not loaded.


1 Answers

I was able to solve the problem by lowering the the security level in "Internet Options" in the Internet zone from "High" to "Medium-high" or "Medium".

like image 62
nelziq Avatar answered Sep 18 '22 14:09

nelziq