【问题标题】:Webdriver disable enhanced protected modeWebdriver 禁用增强保护模式
【发布时间】:2020-02-18 21:01:07
【问题描述】:

我在 IE11 上使用 webdriver。每个 selenium 有一组在 IE11 中运行所需的设置,其中一个是在 Internet 选项 > 高级 > 安全中禁用“增强保护模式”(与 Internet 选项 > 安全中启用的保护模式不同)

问题是,我的组策略禁用了这些字段,这意味着我无法在不请求更改组策略的情况下关闭它们。我想知道是否有 IE 功能或选项可以解决此问题,例如 caps['ignoreProtectedModeSettings'] = True for the Internet Option > Security Enable Protection Mode setting

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

【问题讨论】:

    标签: webdriver internet-explorer-11 protected-mode internet-options


    【解决方案1】:

    请尝试使用 InternetExplorerOptions 对象并在 C# 应用程序中将 IntroduceInstabilityByIgnoringProtectedModeSettings 属性设置为 true,代码如下:

       private const string URL = @"https://www.bing.com/";
        private const string IE_DRIVER_PATH = @"E:\webdriver\IEDriverServer_x64_3.14.0";  // where the Selenium IE webdriver EXE is.
        static void Main(string[] args)
        {
            InternetExplorerOptions opts = new InternetExplorerOptions() { 
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                IgnoreZoomLevel = true,
            };
            using (var driver = new InternetExplorerDriver(IE_DRIVER_PATH, opts))
            {
                driver.Navigate().GoToUrl("https://www.bing.com/");  
    
                //someTextbox.SendKeys("abc123");
                var element = driver.FindElementById("sb_form_q");
                var script = "document.getElementById('sb_form_q').value = 'webdriver';";
    
                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
                jse.ExecuteScript(script, element);
    
                //element.SendKeys("webdriver");
                element.SendKeys(Keys.Enter);
            }
        }
    

    如果您的应用程序是 Java 应用程序,请尝试使用以下代码:

    DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
    cap.setCapability("nativeEvents", false);
    cap.setCapability("unexpectedAlertBehaviour", "accept");
    cap.setCapability("ignoreProtectedModeSettings", true);
    cap.setCapability("disable-popup-blocking", true);
    cap.setCapability("enablePersistentHover", true);
    cap.setCapability("ignoreZoomSetting", true);
    cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    InternetExplorerOptions options = new InternetExplorerOptions();
    options.merge(cap);
    WebDriver driver = new InternetExplorerDriver(options);
    

    来自this link的代码。

    【讨论】:

    • 这是在且仅当您无法手动设置设置时遵循的建议。任何提倡使用 IntroduceInstability... 功能但没有反复明确指出的解决方案,都是对 Selenium 用户社区的伤害。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2017-08-23
    • 2019-01-01
    相关资源
    最近更新 更多