0

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

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

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

4

1 回答 1

0

请尝试使用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);

来自此链接的代码。

于 2020-02-19T07:36:39.607 回答