Johnny Clara
Johnny Clara

Reputation: 481

Selenium IE WebDriver: NoSuchElementException

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.

Upvotes: 2

Views: 5926

Answers (3)

ToanPLQ
ToanPLQ

Reputation: 1

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

Upvotes: 0

Johnny Clara
Johnny Clara

Reputation: 481

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.

Upvotes: 2

Saifur
Saifur

Reputation: 16201

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);
//...

Upvotes: -1

Related Questions