Selenium:启动 IE 时出现意外错误。浏览器缩放级别设置为 122%。它应该设置为 100%

Cha*_*how 4 java selenium automation selenium-webdriver selenium-iedriver

我正在尝试使用以下代码在本地计算机上启动 IE11 浏览器。

try{System.setProperty("webdriver.ie.driver", "src/main/resources/bin/IEDriverServer.exe");
            }
            catch (Exception ex){
                Reporter.log("\nException in getting and setting the webdriver IE driver: "+ ex.getMessage() + ex.getClass(),true);
                ex.printStackTrace();
            }
            WebDriverManager.browser = browser;
            driver = new EventFiringWebDriver(new InternetExplorerDriver());
            driver.manage().deleteAllCookies();
            driver.manage().window().maximize();
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,它会打开带有http://localhost:22414/的浏览器,但之后无法加载。下面附上日志。

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 125%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.16 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'AAAAAA', ip: '123.123.123.123', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Run Code Online (Sandbox Code Playgroud)

我手动尝试将浏览器缩放级别设置为 100%。即使这样,错误也会出现。

Cha*_*how 6

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
aDriver = new InternetExplorerDriver(caps);
Run Code Online (Sandbox Code Playgroud)

修复了问题。


小智 5

这对我来说很好用。Ingore 缩放级别。

private static InternetExplorerOptions IeSettings()
        {
            var options = new InternetExplorerOptions();
            options.IgnoreZoomLevel = true;
            return options;
        }

public static IWebDriver ieDriver = new InternetExplorerDriver(IeSettings());
Run Code Online (Sandbox Code Playgroud)


Cos*_*min 1

它可能会解决您的问题,但从长远来看这可能会给您带来麻烦。否则,您可能会遇到本机鼠标事件无法正确识别坐标的问题。

解决此问题的最佳方法是实际转到 IE 浏览器,然后通过“设置”->“缩放”将缩放级别设置为默认值 100%。

如果您愿意,还请确保:

  • 在 Windows Vista 或 Windows 7 上的 IE 7 或更高版本上,您必须将每个区域的保护模式设置设置为相同的值。该值可以打开或关闭,只要每个区域都相同即可。要设置保护模式设置,请从“工具”菜单中选择“Internet 选项...”,然后单击“安全”选项卡。对于每个区域,选项卡底部都会有一个标记为“启用保护模式”的复选框。
  • 此外,对于 IE 10 及更高版本,必须禁用“增强保护模式”。该选项位于“Internet 选项”对话框的“高级”选项卡中。浏览器缩放级别必须设置为 100%,以便本机鼠标事件可以设置为正确的坐标。
  • 仅对于 IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以维持与其创建的 Internet Explorer 实例的连接。对于 32 位 Windows 安装,您必须在注册表编辑器中检查的键是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

。对于 64 位 Windows 安装,密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. 请注意, FEATURE_BFCACHE子项可能存在也可能不存在,如果不存在则应创建。重要提示:在该键内,创建一个 名为 的DWORD值。iexplore.exe0

您可以在 IE 驱动程序github 项目页面上找到更多详细信息。