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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39564091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:28:29  来源:igfitidea点击:

Selenium: Unexpected error launching IE. Browser zoom level was set to 122%. It should be set to 100%

javaseleniumselenium-webdriverautomationselenium-iedriver

提问by ChanChow

I am trying to launch IE11 browser on my local machine using the following code.

我正在尝试使用以下代码在本地计算机上启动 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();

When I run the code, it brings up the browser with http://localhost:22414/and fails to load there after. Attaching the logs below.

当我运行代码时,它会打开带有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

I manually tried setting the browser zoom level to 100%. Even then the error appears.

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

采纳答案by Cosmin

It may be fixing you the issue, however this could bring you troubles on the long run. Otherwise you may have issues with the native mouse events not identifying the coordinates correctly.

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

Best way to fix this would be to actually go to the IE browser and set the zoom level the default value, 100%, by going to Settings -> Zoom.

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

And if you're at it, also make sure that:

如果您正在使用它,还请确保:

  • On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
  • Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog. The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
  • For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
  • 在 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

. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHEsubkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORDvalue named iexplore.exewith the value of 0.

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

You can find more details on the IE Driver github project page.

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

回答by ChanChow

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
aDriver = new InternetExplorerDriver(caps);

Fixed the issue.

修复了问题。

回答by Miroslav Mikolaj

This is working fine for me. Ingore that zoom level.

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

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

public static IWebDriver ieDriver = new InternetExplorerDriver(IeSettings());

回答by Doug Noel

DesiredCapabilities has been deprecated. The official way to do this now is to use InternetExplorerOptions. When adding these two lines, be sure that you are passing it as an argument when instantiating the driver.

DesiredCapabilities 已被弃用。现在执行此操作的官方方法是使用 InternetExplorerOptions。添加这两行时,请确保在实例化驱动程序时将其作为参数传递。

InternetExplorerOptions capabilities = new InternetExplorerOptions();
capabilities.ignoreZoomSettings();
driver = new InternetExplorerDriver(capabilities);

回答by Bharath

System.setProperty("webdriver.ie.driver",".\browserDrivers\IEDriverServer.exe");

DesiredCapabilities capability = DesiredCapabilities.internetExplorer();

capability.setCapability("ignoreZoomSetting", true);
                 capability.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "");

driver = new InternetExplorerDriver(capability);