1

我的 selenium 测试用例在 internet explorer 11 浏览器上执行得很好,但是有些事情发生了变化,现在我得到了以下错误。

Started InternetExplorerDriver server (64-bit)
3.13.0.0
Listening on port 32274
Only local connections are allowed
[ERROR] [BaseTest] [startWebDriverClient] Could not start a new session.      org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:32274/'
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'LUSMIN-F00Q46Y', ip: '***.**.**.**', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '9.0.1'
Driver info: driver.version: unknown
remote stacktrace: 
    at com.tcs.saf.base.BaseTest.startWebDriverClient(BaseTest.java:496)
    at com.tcs.saf.base.BaseTest.beforeMethod(BaseTest.java:258)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:451)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:516)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)

下面是我实例化 IE 浏览器的代码;

if (browserType.equalsIgnoreCase("InternetExplorer")) {
            try {
                System.setProperty("webdriver.ie.driver", curProj+"\\drivers\\IEDriverServer.exe");             
                InternetExplorerOptions options = new InternetExplorerOptions();
                options.introduceFlakinessByIgnoringSecurityDomains();
                options.requireWindowFocus();               
                webdriver = new InternetExplorerDriver(options);
                logger.info("getWebDriver - Setting webdriver.ie.driver system property as: " + System.getProperty("webdriver.ie.driver"));
            } catch(IllegalStateException e) {
                logger.error("The path to the driver executable must be set by the webdriver.ie.driver system property. ",e.fillInStackTrace());
                throw new IllegalStateException("The path to the driver executable must be set by the webdriver.ie.driver system property.");
            }
        }
4

3 回答 3

0

此错误消息...

Could not start a new session. org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:32274/'

...暗示IEDriverServer无法启动/产生新的WebBrowserIE 浏览器会话。


根据启动 Internet Explorer 的意外错误。IELaunchURL() 返回 HRESULT 80070012 ('没有更多文件。') @JimEvans 明确提到:

IELaunchURL() 函数是一个 Windows API。司机只是简单地调用它。如果它返回一个错误,那么这就是问题所在。Microsoft 没有提供有关在使用此 API 时会导致此错误的原因的文档。如果您尝试在 Windows 10 等工作站级操作系统而不是 Windows Server 上运行测试,会发生什么情况?我意识到这不是一个“灵丹妙药”的解决方案,但在服务器环境中可能存在一些不在工作站环境中的安全设置,这些设置会阻止在该上下文中分配额外的文件句柄。


引入FlakinessByIgnoringSecurityDomains();

正如您添加的选项introduceFlakinessByIgnoringSecurityDomains();一样,您做错了:IE 保护模式和 WebDriver @JimEvans 再次清楚地提到添加options.introduceFlakinessByIgnoringSecurityDomains();可能会让您摆脱最初的异常,并允许测试在大多数情况下运行而不会发生意外。但是,使用此功能并不能解决根本问题。如果跨越保护模式边界,可能会发生非常意外的行为,包括挂起元素位置不工作点击不传播


解决方案

如果您查看Internet Explorer 驱动程序的所需配置,则会清楚地提到以下几点:

保护模式

在 Windows Vista 或 Windows 7 上的 Internet Explorer 7 或更高版本上,您必须将每个区域的保护模式设置设置为相同的值。该值可以打开或关闭,只要每个区域都相同。要设置保护模式设置,您必须从“工具”菜单中选择“Internet 选项”,然后单击“安全”选项卡。对于每个区域,标签底部都有一个标记为Enable Protected Mode的复选框。

保护模式设置

浏览器缩放级别

浏览器缩放级别必须设置为 100%,以便可以将本机鼠标事件设置为正确的坐标。

参考

您可以在以下位置找到一些详细的讨论:

于 2018-07-04T08:57:32.667 回答
0

请尝试下面提到的步骤,然后尝试运行 IE 浏览器的自动化脚本。

  1. 仅对于 IE 11,您需要在目标计算机上设置一个注册表项,以便驱动程序可以保持与它创建的 Internet Explorer 实例的连接。对于 32 位 Windows 安装,您必须在注册表编辑器中检查的项是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

  2. 对于 64 位 Windows 安装,密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。

请注意,FEATURE_BFCACHE 子项可能存在也可能不存在,如果不存在,则应创建它。在此键中,创建一个名为 iexplore.exe 且值为 0 的 DWORD 值。

所有区域的保护模式设置都相同。增强保护模式被禁用。

于 2018-07-04T05:44:49.730 回答
0

根据错误日志,您使用的是 java 9。Selenium 尚不支持 Java 9。请更改设置以使用 java 8 并重试。它可能会解决问题。

于 2018-07-04T05:47:34.120 回答