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


我原来在用

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


调整WebDriver的大小,但是当这似乎是问题的根源时,我切换到了工具箱。经过进一步检查,我发现它实际上只是出于某种未知原因而找不到驱动程序。

我在进行了更多堆栈溢出搜索之后添加了功能对象,但这也没起作用。

我也将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中打开一个窗口,请在SetSize中使用隐式等待

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


包括

import org.openqa.selenium.Dimension;

关于java - Selenium 在IE11浏览器窗口初始化后立即抛出NoSuchWindowException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38226459/

10-15 23:38