1

I've been trying to run every type of browser in a testing session, and unfortunately that includes IE. The browser window initializes perfectly fine, but when I try to resize it through Selenium, it immediately throws a "NoSuchWindowException".

    // Set path for Internet Explorer Driver executable
    System.setProperty("webdriver.ie.driver", "./IEDriverServer.exe");

    // Launch InternetExplorerDriver
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); 
    driver = new InternetExplorerDriver(capabilities);

    driver.get(address);

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    int Width = (int) toolkit.getScreenSize().getWidth();
    int Height = (int)toolkit.getScreenSize().getHeight();
    System.out.println(driver.toString());
    driver.manage().window().setSize(new Dimension(Width,Height));

I was originally using

    driver.manage().window().maximize(); 

to resize the WebDriver, but when that seemed to be the source of the issue i switched to toolkit. Upon further inspection I found that it really is just not finding the driver for some unknown reason.

I added the capabilities object after a little more stack overflow searching, but that also didnt work.

I have set IE11 protected mode to enabled, too.

Error message:

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
4

1 回答 1

1

试试这个代码

在 IE11 中打开一个窗口后,在 setSize 之前使用隐式等待

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

包括

import org.openqa.selenium.Dimension;
于 2016-07-07T07:30:32.227 回答