Selenium IE WebDriver:NoSuchElementException [英] Selenium IE WebDriver: NoSuchElementException

查看:118
本文介绍了Selenium IE WebDriver:NoSuchElementException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium Internet Explorer WebDriver,但是一旦我尝试在已加载页面中找到一个元素,它就会不断抛出异常.

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.

我正在使用Windows 8.1 x64计算机上运行的Selenium客户端和2.44版Internet Explorer 11(我尝试过32位和64位版本)的.NET实现.

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.

这是我正在使用的C#测试代码:

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>

该异常在进入driver.FindElement(By.Name("name"))调用后立即引发.在此之前,执行将按预期工作(在实例化Webdriver时启动IE并正确导航到URL).

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

这是我得到的例外:

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)

我已将IE中的所有安全区域设置为具有相同的保护模式设置(尝试所有启用和全部禁用),禁用了增强保护模式,并已按照官方网站( https://code.google.com/p/selenium/wiki/InternetExplorerDriver ).我试图显式地等待60秒,以防在执行到该点时尚未加载网页.没有运气.

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.

感谢您的帮助.

推荐答案

更新KB3025390 可使WebDriver与Internet Explorer 11一起正常工作.

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.

这篇关于Selenium IE WebDriver:NoSuchElementException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆