【问题标题】:Selenium test in Internet Explorer in InPrivate modeInPrivate 模式下 Internet Explorer 中的 Selenium 测试
【发布时间】:2018-09-17 17:41:32
【问题描述】:

有什么方法可以在 Internet Explorer 9 中使用 IEDriverServer 以 InPrivate 模式运行 Selenium 自动化测试? 我需要测试 2(两个)测试用例:
1.浏览器关闭。打开一个 IE InPrivate 模式的窗口。运行测试。
2. 浏览器以正常模式打开。打开 IE InPrivate 模式的新窗口。运行测试。

JAVA 代码应如何查找此测试?
谢谢

【问题讨论】:

    标签: java internet-explorer selenium selenium-webdriver


    【解决方案1】:
    public void openBrowserInPrivacyMode(boolean isBrowserActive) {
        System.setProperty("webdriver.ie.driver", "path/to/IEDriverServer_x32.exe"); 
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();  
        capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);  
        сapabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
        InternetExplorerDriver driver = new InternetExplorerDriver(capabilities);
    

    【讨论】:

      【解决方案2】:

      @Roman 的解决方案is now deprecated.

      新的方法如下:

      InternetExplorerOptions ieOptions = new InternetExplorerOptions();
      ieOptions.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
      ieOptions.addCommandSwitches("-private");
      InternetExplorerDriver driver = InternetExplorerDriver(ieOptions));
      

      另外,在我设置TabProcGrowth 注册表值之前,我在执行此操作时遇到了问题。在这样做之前,我遇到了以下异常:

      org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer.
      Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher,
      the value of registry setting in
      HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'.
      

      我在 Windows 10 和 Selenium 3.14 上遇到过这种情况。奇怪的是,我还为我设置了 TabProcGrowth 值 fixed this

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-14
        • 2017-09-14
        • 2011-12-20
        相关资源
        最近更新 更多