使用Selenium Webdriver时,我使用InternetExplorerDriver收到以下错误 - "启动Internet Explorer时出现意外错误...."

Yor*_*nno 21 c# webdriver selenium-webdriver

我正在尝试在C#中实例化InternetExplorerDriver,每次我都会收到以下错误消息:

System.InvalidOperationException:启动Internet Explorer时出现意外错误.必须将保护模式设置为所有区域的相同值(启用或禁用).(NoSuchDriver)

现在我不确定如何解决这个问题,但触发错误的代码行是:

IWebDriver driver = new InternetExplorerDriver();
Run Code Online (Sandbox Code Playgroud)

对于InternetExplorerDriver文档建议,我可以在通过ICapabilities对象在重载的构造,但是仅具有的属性BrowserName,IsJavaScriptEnabled,Platform和Version.这些似乎都没有暗示他们可以解决这个问题.

在实现中我需要做些什么来解决这个问题吗?或者我是否必须修改IE9本身的一些设置?

Ral*_*oss 27

作为参考,如果您希望覆盖这里的安全选项是c#代码:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;

namespace SeleniumTests
{
    [TestFixture]
    public class Test
    {
       private IWebDriver driver;

       [SetUp]
       public void Setup()
       {
          var options = new InternetExplorerOptions();
          options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
          driver = new InternetExplorerDriver(options);
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

更新:
我之前的回答使用了旧版本的Selenium 2.0,我现在更新了代码以对抗Selenium DotNet-2.21.0并包含正确的命名空间.


Chr*_*uts 17

Internet Explorer定义了四个区域,每个区域具有不同的安全级别,并且能够启用或禁用保护模式.错误消息试图告诉您,由于Selenium的限制,必须禁用或启用所有区域的保护模式InternetExplorerDriver.

有关更多详细信息,请参阅Selenium问题跟踪器中的缺陷报告以及Internet Explorer安全选项的屏幕截图.

  • Nope仍然为我打破..我没有登录谷歌(如果我需要登录才能看到它,它实际上并不在网上) (5认同)

Ale*_*uhi 8

这应该解决问题:

InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver driver = new InternetExplorerDriver(options);
Run Code Online (Sandbox Code Playgroud)


小智 5

Aleh's Answer为我解决了这个问题,但是我发现我还需要指定.path的文件路径IEDriverServer。只是在万一其他人遇到类似问题的情况下发布。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;

namespace SeleniumTest
{
    class Program
    {
        static void Main(string[] args)
        {
            InternetExplorerOptions options = new InternetExplorerOptions();
            options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

            IWebDriver driver = new InternetExplorerDriver("C:\\Selenium", options);

            driver.Navigate().GoToUrl("http://www.stackoverflow.com");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)