Java 初始化IE11浏览器窗口后,立即引发NoSuchWindowException

Java 初始化IE11浏览器窗口后,立即引发NoSuchWindowException,java,selenium,selenium-webdriver,internet-explorer-11,selenium-iedriver,Java,Selenium,Selenium Webdriver,Internet Explorer 11,Selenium Iedriver,我一直在尝试在测试会话中运行每种类型的浏览器,不幸的是,其中包括IE。浏览器窗口初始化非常好,但当我尝试通过Selenium调整其大小时,它立即抛出“NoSuchWindowException” 我最初使用的是 driver.manage().window().maximize(); 调整WebDriver的大小,但当这似乎是问题的根源时,我切换到toolkit。经过进一步的检查,我发现这真的只是因为一些未知的原因找不到司机 我在进行了更多的堆栈溢出搜索之后添加了capabiliti

我一直在尝试在测试会话中运行每种类型的浏览器,不幸的是,其中包括IE。浏览器窗口初始化非常好,但当我尝试通过Selenium调整其大小时,它立即抛出“NoSuchWindowException”

我最初使用的是

    driver.manage().window().maximize(); 
调整WebDriver的大小,但当这似乎是问题的根源时,我切换到toolkit。经过进一步的检查,我发现这真的只是因为一些未知的原因找不到司机

我在进行了更多的堆栈溢出搜索之后添加了capabilities对象,但这也不起作用

我也将IE11保护模式设置为启用

错误消息:

Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Error retrieving window with handle current (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'WIN-HHUFCN1FEP8', ip: '127.0.0.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, proxy={proxyType=}, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:47406/, javascriptEnabled=true, ignoreProtectedModeSettings=true, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: d01a13ab-53e9-46f6-a19e-00d19ea5f34c
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:891)
    at Testing.Testing.main(Testing.java:124)
C:\...\NetBeans\Cache\8.1\executor-snippets\debug.xml:83: Java returned: 1
试试这个代码

在IE11中打开窗口后,在设置大小之前使用隐式等待

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1024,768));
包括

import org.openqa.selenium.Dimension;

可能复制的哦,然后成功!享受:)
import org.openqa.selenium.Dimension;