2

I'm trying to get to work Selenium Internet Explorer WebDriver, but it keeps throwing an exception as soon as I try to find an element inside the loaded page.

I'm using .NET implementation of Selenium client and version 2.44, Internet Explorer 11 (I've tried 32-bit and 64-bit versions) running on a Windows 8.1 x64 machine.

This is the C# test code I'm using:

IWebDriver driver = new InternetExplorerDriver();

driver.Navigate().GoToUrl("http://mytesturl.com");

const string name = "Test";

IWebElement nameElement = driver.FindElement(By.Name("name"));
nameElement.SendKeys(name);
//...

This is the Web page on which I'm running the test:

<!DOCTYPE html>
<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>TestSelenium</title>
</head>
<body>
    <div>
        <form action="<%: Url.Action("TestSeleniumFormResponse") %>" method="post">
            Insert name: <input name="name" type="text"/>
            <button type="submit">Submit</button>
        </form>
    </div>
</body>
</html>

The exception is raised as soon as it gets to the driver.FindElement(By.Name("name")) call. Until then, the execution works as expected (launches IE when the webdriver is instantiated and navigates to the URL correctly).

This is the exception I'm getting:

OpenQA.Selenium.NoSuchElementException : Unable to find element with name == name
   en OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   en OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   en OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   en OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByName(String name)
   en OpenQA.Selenium.By.<>c__DisplayClassa.<Name>b__8(ISearchContext context)
   en OpenQA.Selenium.By.FindElement(ISearchContext context)
   en OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)

I've got all security zones in IE set to have the same protected mode settings (tried with all enabled and all disabled), enhanced protection mode disabled, and have set the registry entries as specified in the required configuration section of the official website (https://code.google.com/p/selenium/wiki/InternetExplorerDriver). I've tried to explicitly wait up to 60 seconds, in case the webpage wasn't loaded by the time the execution reaches that point. No luck.

Thanks for your help.

Johnny Clara
  • 481
  • 6
  • 18
  • 6
    Have you checked to see if [Microsoft Update KB3025390](https://support.microsoft.com/kb/3025390) is installed? That update renders the IE driver [useless with IE 11](http://jimevansmusic.blogspot.com/2014/12/windows-update-kb3025390-for-ie-11.html). A [bug report](https://connect.microsoft.com/IE/feedback/details/1062093/installation-of-kb3025390-breaks-out-of-process-javascript-execution-in-ie11) has been filed with Microsoft, and the issue is being tracked in the [Selenium issue tracker](https://code.google.com/p/selenium/issues/detail?id=8302). – JimEvans Jan 08 '15 at 15:54

3 Answers3

2

As reported by @JimEvans on the question's comments, it was a Windows update what was causing the IE WebDriver to not work properly. Uninstalling the update KB3025390 has made the WebDriver work correctly with Internet Explorer 11.

I know this is far from the best kind of solution, but as long as it works (and there's already a bug report on this), it's OK for me.

Community
  • 1
  • 1
Johnny Clara
  • 481
  • 6
  • 18
  • According to the information there: This issue is resolved in [update 3034762](http://support.microsoft.com/kb/3034762). And we recommend that you install the [Description of the security update for Internet Explorer: February 10, 2015 (MS15-009)](http://support2.microsoft.com/kb/3021952) that fixes many other issues in addition to the issue that this update fixes. – JNF Mar 22 '15 at 07:39
0

I stuck at this thing 2 days without any solution. I try in 2 machine and result is 1 machine is going well and 1 is not. After compare them I find out my mistake is I am missing 1 line in my code, so it's can't get the element ID. Try this:

[TestInitialize()]
     public void MyTestInitialize() {
         driver = new InternetExplorerDriver();
         driver.Manage().Window.Maximize();

     }

Please notice line the line driver.Manage().Window.Maximize(); Hope this help!! :D

Robert
  • 5,278
  • 43
  • 65
  • 115
-1

Try the following: It disable IE native event and add 10s implicit wait after instantiating the browser. And, Just to clarify the browser zoom level should be 100% as well.

var options = new InternetExplorerOptions{EnableNativeEvents = false};
IWebDriver driver = new InternetExplorerDriver(options);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
driver.Navigate().GoToUrl("http://mytesturl.com");

const string name = "Test";
IWebElement nameElement = driver.FindElement(By.XPath("//input[@name='name']"));
nameElement.SendKeys(name);
//...
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Sorry, I forgot to mention it: I'm already using the 100% zoom level. I've tried your solution, but I still get the same exception. However, using `By.XPath` instead of `By.Name` throws now an InvalidSelectorException: The xpath expression '//input[@name='name']' cannot be evaluated or does notresult in a WebElement. Thank you for your time. – Johnny Clara Jan 08 '15 at 13:49
  • @JohnnyClara Is it a public site? Can you provide me the actual URL? – Saifur Jan 08 '15 at 13:52
  • It isn't, but you should have no trouble using the HTML I provided on the question (forget about the form's action). The C# code should make the browser write the word "Test" on the input. – Johnny Clara Jan 08 '15 at 14:00