4

在 Windows7 和 Firefox 中使用 Selenium IDE,自动单击链接可能会生成新选项卡或新窗口。

close() 关闭原始窗口或选项卡,而不是新的。也许如果我有新创建的 ID,我可以选择它然后关闭它,但我不知道如何自动执行此操作。我在 Selenium 论坛上提问并阅读了这里的问题,但他们关注的是 WebDriver,而不是 IDE。任何帮助,将不胜感激!

 Stig
4

5 回答 5

7

我遇到了同样的问题并找到了解决方案:

  1. 单击打开新选项卡的链接
  2. 添加命令waitForPopUp
  3. 通过命令将焦点设置到新选项卡selectPopUp
  4. 在新标签中对您的内容进行验证或其他命令
  5. 使用命令close关闭选项卡
  6. 使用命令selectWindow将焦点设置到旧窗口

我的 Selenium IDE 命令的屏幕截图:

Selenium IDE 切换选项卡

这对我行得通。

于 2013-08-15T12:24:55.183 回答
0

在 Se IDE 中使用selectWindow(windowID)命令切换到新窗口。您可以通过 windowID/name/title 选择新窗口。

希望这可以帮助...

于 2012-12-20T15:35:49.113 回答
-1

selectWindow(windowID) 可以选择提及网页/窗口的标题作为识别目标窗口的一种方式。

语法 = selectWindow title=我的特殊窗口

注意:title = 在网页标题栏中可见的网页标题。或右键单击网页并选择菜单“页面来源”。在源文档中,选择...之间的文本。

所以如果网页的标题=我的特殊窗口,你会看到我的特殊窗口。

希望这会有所帮助。

斯瓦萨蒂保罗

于 2014-03-26T14:57:24.380 回答
-1

同意surya使用selectWindow(windowID),您可以通过右键单击页面检查选项verifyTitle来获取窗口标题,并在前面您有您的标题。希望它有所帮助。

于 2012-12-27T11:24:37.253 回答
-1

您可以使用迭代器在窗口之间进行迭代,关闭新窗口并返回到原来的窗口。你可以把它放在try块下,因为它只会在新窗口打开时迭代。否则,它将在当前窗口中继续正常执行。

try{     
Set <Strings> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentPage = it.next();
String newPage = it.next();
driver.switchTo().window(newPage);
driver.close(); //it will close the new window and automatically come back to the currentPage
}
finally
{
//continue with your script here
//this script will run regardless of the execution of the execution of the try block
}
于 2017-09-07T03:05:27.430 回答