大家好,
我是 selenium 网络自动化工具的新伙伴。我遇到了一个场景,我需要在 Facebook 登录窗口页面中发送登录凭据以完成我的测试用例。因此,请提供帮助或提供一些建议以传递凭据并登录到 Facebook 帐户。
我尝试使用 Selenium IDE 并记录我的测试脚本,但在运行记录的脚本时,我无法访问该特定对话框窗口。
下面我附上了我的场景图片
提前致谢。
经过大量的尝试,我能够通过使用以下代码实现上述场景。
String winHandleBefore = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
请试试这个
//Store the current window handle
String winHandleBefore = driver.getWindowHandle();
//Perform the click operation that opens new window
//switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
//Perform the actions on new window
//close the new window, if that window no more required
driver.close();
//Swithc back to original browser (first window)
driver.switchTo().window(winHandleBefore);
//continue with original browser (first window)