Selenium-无法获取子窗口的窗口句柄并且执行子窗口未关闭时

时间:2018-07-30 06:57:58

标签: java windows selenium selenium-webdriver

我在硒项目中关闭Web弹出窗口时遇到困难,在我使用的代码下面,执行时,未捕获子窗口ID可能是什么错误?

try{
driver.get(baseURL);

Thread.sleep(1000);

clearAndType(driver, textUserName, userName);

clearAndType(driver, textPassword, password);

click(driver,btnLoggin);

String parentWindow = driver.getWindowHandle();

Set<String> handles = driver.getWindowHandles();

for(String windowHandle : handles)
{ 
System.out.println("$$$$$$$$$$--"+parentWindow);

System.out.println("%%%%%%%%%%--"+windowHandle);

System.out.println("&&&&&&&--"+handles);

if(!windowHandle.equals(parentWindow))

{

driver.switchTo().window(windowHandle);

//<-------Perform your operation here for new window--->

driver.close(); //closing child window

driver.switchTo().window(parentWindow); //cntrl to parent window

}

}


/////////////////////////////////////////////////////////////////////////////////

return new FNDashBoardPage(driver);

}

catch(Exception ex){

throw ex;

堆栈跟踪

$$$$$$$$$$--c1abc88f-4e98-487e-9a09-b044a6fa0829

%%%%%%%%%%--c1abc88f-4e98-487e-9a09-b044a6fa0829

&&&&&&&--[c1abc88f-4e98-487e-9a09-b044a6fa0829] - In here only captured parent window ID
[TestNG] Running:
  C:\Users\malithm\AppData\Local\Temp\testng-eclipse-843910861\testng-customsuite.xml


Started InternetExplorerDriver server (32-bit)
2.44.0.0

Listening on port 33154

Jul 30, 2018 11:41:24 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute

INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed

Jul 30, 2018 11:41:24 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute

INFO: Retrying request

Window is closed (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds

Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'

System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_67'

Session ID: e6d26fbe-0efc-4457-913f-8520f2f59b55

Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities

[{platform=WINDOWS,javascriptEnabled=true,elementScrollBehavior=0,ignoreZoomSetting=false,enablePersistentHover=true,ie.ensureCleanSession=false,

browserName=internet explorer, enableElementCacheCleanup=true, 
unexpectedAlertBehaviour=dismiss, version=11,

ie.usePerProcessProxy=false, ignoreProtectedModeSettings=false,

 cssSelectorsEnabled=true, requireWindowFocus=false,

initialBrowserUrl=http://localhost:33154/, handlesAlerts=true,

ie.forceCreateProcessApi=false, nativeEvents=true,

browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]

Jul 30, 2018 11:41:44 AM org.openqa.selenium.support.ui.ExpectedConditions findElement

WARNING: WebDriverException thrown by findElement(By.xpath: .//*[@id='myAccordion']/div[10]/a)

org.openqa.selenium.NoSuchWindowException: Unable to find element on closed

window (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20 milliseconds

Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'

System info: os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_67'

Session ID: e6d26fbe-0efc-4457-913f-8520f2f59b55

Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,

ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false,
browserName=internet explorer, enableElementCacheCleanup=true,
unexpectedAlertBehaviour=dismiss, version=11,

ie.usePerProcessProxy=false, ignoreProtectedModeSettings=false, cssSelectorsEnabled=true,

requireWindowFocus=false, initialBrowserUrl=http://localhost:33154/, handlesAlerts=true,

ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)

0 个答案:

没有答案