我在一个场景中执行以下步骤:
driver.switchTo()切换到子窗口。window(句柄)
-->在子窗口上执行操作。步骤1到3工作很好。但是步骤4抛出了一个异常。为了更清楚,我在抛出异常之前包含了日志消息。n
// Switching to child window
[testng] 23:40:33.794 INFO - Executing: [switch to window: 3efe9598-2a08-40ec-a950-d4a6e2182b20])
[testng] W 2016-02-08 23:40:33:808 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
[testng] W 2016-02-08 23:40:33:821 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
[testng] 23:40:33.942 INFO - Done: [switch to window: 3efe9598-2a08-40ec-a950-d4a6e2182b20]
[testng] 23:40:33.944 INFO - Executing: [get title])
[testng] 23:40:33.955 INFO - Done: [get title]
[testng] 23:41:34.708 INFO - Executing: [close window])
[testng] 23:41:34.719 INFO - Done: [close window]
// Switch to parent window
[testng] 23:41:34.751 INFO - Executing: [switch to window: b2dd5b6e-c891-498f-871b-1fc80b4afef2])
[testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
[testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(504) Unable to find current browser
[testng] W 2016-02-08 23:41:34:765 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
[testng] W 2016-02-08 23:41:34:865 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
[testng] W 2016-02-08 23:42:34:875 response.cc(69) Error response has status code 21 and message 'Timed out waiting for page to load.' message
[testng] 23:42:34.879 WARN - Exception thrown
[testng] org.openqa.selenium.TimeoutException: Timed out waiting for page to load. (WARNING: The server did not provide any stacktrace information)
[testng] Command duration or timeout: 60.13 seconds
[testng] Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
[testng] System info: host: 'x-x-x-x', ip: 'x.x.x.x', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
[testng] Driver info: org.openqa.selenium.ie.InternetExplorerDriver
[testng] Capabilities [{browserAttachTimeout=0, enablePersistentHover=false, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:42778/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=true, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=accept}]`
我们正在使用一个基于flashSelenium的特殊框架,这里的开发人员已经成功地将flash Selenium与WebDriver集成在一起(最初flash Selenium是用来与RC一起工作的)。根据我的理解,我们的框架涉及flashSelenium、RC和Webdriver组件。我是这个团队的新手,框架API还没有在积极开发中(没有支持)。
当我在步骤4周围放置try catch时,步骤5将正确执行。我可以看到异常阻止了步骤4打印错误!!
所以我的问题来了:driver.switchTo().window(parentWindow)在任何情况下是否会给出如上所示的异常?
从下面的日志片段中,我可以看到到window的切换执行了,但是switch window的内部方法抛出了一个异常,这是连续行提示的。
[testng] 23:41:34.751 INFO - Executing: [switch to window: b2dd5b6e-c891-498f-871b-1fc80b4afef2])
[testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
[testng] W 2016-02-08 23:41:34:753 IECommandExecutor.cpp(504) Unable to find current browser
[testng] W 2016-02-08 23:41:34:765 Browser.cpp(241) Unable to get window name, IHTMLWindow2::get_name failed or returned a NULL value
[testng] W 2016-02-08 23:41:34:865 IECommandExecutor.cpp(595) Unable to find managed browser with id 3efe9598-2a08-40ec-a950-d4a6e2182b20
[testng] W 2016-02-08 23:42:34:875 response.cc(69) Error response has status code 21 and message 'Timed out waiting for page to load.' message
[testng] 23:42:34.879 WARN - Exception thrown
代码如下所示
String parentHandle = driver.getWindowHandle();
// Click on the element code goes here (This is in flash selenium)
Set<String> windowhandles = driver.getWindowHandles();
for (String windowHandle : windowHandles) {
driver.switchTo().window(windowHandle);
}
System.out.println("Child title : " + driver.getTitle());
driver.close;
// Exception is thrown in the below line. If a try catch is placed
// the last line gets executed (sysout). But I can see the catch getting executed.
driver.switchTo().window(parentHandle);
System.out.println("Child title : " + driver.getTitle());
您是正确的,Selenium在使用driver.close()
后不会自动切换到父窗口。当您尝试driver.switchTo().window(currentWindow)
时,驱动程序仍然专注于关闭窗口的窗口句柄,这是导致无法找到id为3EFE9598-2A08-40EC-A950-D4A6E2182B20
的托管浏览器和无法找到当前浏览器
消息的原因。
如果您想切换回父句柄,您应该在切换之前保存它
String parentHandle = driver.getWindowHandle();
driver.switchTo().window(childHandle); // switch to child window
driver.close(); // close child window
driver.switchTo().window(parentHandle); // switch focus back to parent window
我正在IE上测试。单击后,我切换到子窗口,但无法返回父窗口,出现错误“窗口已关闭”。
脚本: 单击父窗口中的审核按钮 子窗口已加载 将控件切换到子窗口 单击子窗口中的“确定”按钮 窗口关闭 从父窗口继续测试 在这里,我面临的挑战是在单击“确定”按钮后切换到父窗口。当窗户关闭时。 硒网络驱动程序:2.48
我正面临以下错误!!
本文向大家介绍c# 实现子窗口关闭父窗口也关闭的方法,包括了c# 实现子窗口关闭父窗口也关闭的方法的使用技巧和注意事项,需要的朋友参考一下 其实是窗口间通讯的问题,在form1上打开form2 ,form2 关闭时关闭form1 实现方法: 在子窗口form2中声明事件: 然后在它的关闭事件中触发本事件: 在父窗口form1中(比如登陆窗口中): 然后弹出子form2窗体的地方这样写: 以上这篇c