16

Currently, I am working on WebDriver to invoke IE browser to run the testing. But I received a NoSuchElementException when I tried to run the simple example below.

However, the code just worked fine if I used Chrome Driver or Firefox driver. Any idea or thought would be appreciated.

Jar: selenium-server-standalone-2.5.0.jar

Code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public static void main(String[] args) throws InterruptedException {
  DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
  ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
  WebDriver driver = new InternetExplorerDriver(ieCapabilities);
  driver.get("www.google.com");
  driver.findElement(By.name("q"));
}

Error message:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with name == q (WARNING: The server did not provide any stacktrace information)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:29:57'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_25'
Driver info: driver.version: RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:197)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:246)
    at org.openqa.selenium.By$ByName.findElement(By.java:298)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:189)
    at lib.WebDriver2.main(WebDriver2.java:14)
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
user836112
  • 353
  • 3
  • 7
  • 14
  • That stacktrace/error message looks incomplete, are you sure that it's complete? – Jasper Sep 02 '11 at 06:28
  • Hi, updated the error message :) IE browser was opened and directed to google page. But, it failed as it tried to find the element "q" – user836112 Sep 02 '11 at 17:17
  • same issue here. I'm using a 64bit system, but with a 32 bit jvm, so the driver is 32 bit too. Nothing listed below helped – Artur Gajowy Sep 05 '11 at 13:55
  • 1
    You've explicitly avoided having to set the Protected Mode settings of IE. That's what the `InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS` capability setting does. What happens if you remove this capability setting and set the Protected Mode settings as documented in the [project wiki](http://code.google.com/p/selenium/wiki/InternetExplorerDriver)? – JimEvans Sep 07 '11 at 10:41
  • 1
    Hi JimEvans, Thanks a lot for your help!! I removed the "ieCapabilities". Instead, I went to Internet option and followed the steps as Project Wiki. It works for me right now. The most important information is "you must set the Protected Mode settings for each zone to be the same value." Again, thanks for your help. – user836112 Sep 08 '11 at 23:26
  • Great. Promoting this comment to an answer, so that you can accept it. – JimEvans Oct 07 '11 at 13:23

3 Answers3

14

You've explicitly avoided having to set the Protected Mode settings of IE. That's what the InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS capability setting does. When you remove this capability setting and set the Protected Mode settings as documented in the project wiki, it seems the problem resolves itself.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • Hi Jim. Thanks for the solution. I do not have any privileges to modify the security settings. Is there a workaround? Thanks! – sbose Feb 04 '13 at 07:06
  • The capability **is** the workaround. [This blog post](http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html) describes the technical reasons why the Protected Mode settings matter and why your organization is actively sabotaging your ability to get your work done if they don't allow you to change the setting. – JimEvans Feb 04 '13 at 12:37
5

Try adding implicitly wait like below. Also as Robert said, your URL should have http://

WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
nilesh
  • 14,131
  • 7
  • 65
  • 79
2

There was a short FAQ entry on the project website (copied circa Selenium 2.9):

The InternetExplorerDriver requires that all security domains are set to the same value (either trusted or untrusted) If you're not in a position to modify the security domains, then you can override the check like this:

DesiredCapabilities capabilities =
DesiredCapabilities.internetExplorer();
capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true); 
WebDriver driver = new InternetExplorerDriver(capabilities);

As can be told by the name of the constant, this may introduce flakiness in your tests. If all sites are in the same protection domain, you should be okay.

The parallel C# InvalidOperationException message:

Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver)

and the C# instead of adjusting IE settings (best guess as of Feb 2016):

var ieOptions = new OpenQA.Selenium.IE.InternetExplorerOptions {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true };
using (var driver = new InternetExplorerDriver(ieOptions))
{

This was all part of issue 1795 on the Selenium issue tracker.

user423430
  • 3,654
  • 3
  • 26
  • 22