public Wrapper SwitchToWindowWithName()
{
try {
//driver.switchTo().window(newstrWindowName);
//Switch to new window opened
foreach(String handler in driver.WindowHandles)
driver.SwitchTo().Window(handler);
}
catch(Exception e) {
reporter.WriteToTestLevelReport("Switch Window", "Switch to new Window ", "Exception occured : " + e.Message, "Fail");
throw (e);
}
return this;
}
public Wrapper SwitchToFrameWithName(String frameName)
{
driver.SwitchTo().Frame(frameName);
return this;
}上面的代码是在包装器中定义的,用于处理应用程序中出现的新窗口或框架。上面的代码在用于我的一个应用程序时工作得很好,但同样的代码不能用于处理新窗口的另一个应用程序。在我的应用程序中有一个名为"View Result“的按钮。单击查看结果按钮时,将打开一个窗口,然后单击一个按钮。目前,我的代码单击了"View Result“按钮,但确实单击了新窗口中的按钮。请让我知道更多的信息。我已经添加了2张图片截图。第一个屏幕截图突出显示了"View result“按钮。第二个屏幕截图是在运行脚本时出现在新窗口上的页面。

发布于 2018-05-17 21:37:28
您可以使用window而不是frame在选项卡之间切换吗?到目前为止,我的理解是你不能使用frame在两个标签页之间切换。使用frame只适用于同一页面上的元素,例如警告、弹出窗口等。要根据屏幕截图执行相应操作,必须切换窗口。
public Wrapper SwitchToWindowWithName(String window)
{
driver.SwitchTo().Window(window);
return this;
}https://stackoverflow.com/questions/50392401
复制相似问题