如何使用selenium ide关注新窗口?

如何使用selenium ide关注新窗口?,selenium,automated-tests,selenium-ide,Selenium,Automated Tests,Selenium Ide,我正在尝试使用selenium ide复制操作。操作是单击打开新窗口的链接。如何使selenium ide关注新窗口而不是另一个窗口?它对我不起作用。选择窗口 为此,您需要使用selectWindow | windowName命令 要从另一个窗口返回主窗口,请执行选择window | null 已选择,则所有命令都转到 那扇窗户。选择主窗口 同样,使用null作为目标 Window locators provide different ways of specifying the window

我正在尝试使用selenium ide复制操作。操作是单击打开新窗口的链接。如何使selenium ide关注新窗口而不是另一个窗口?它对我不起作用。

选择窗口

为此,您需要使用
selectWindow | windowName
命令

要从另一个窗口返回主窗口,请执行
选择window | null

已选择,则所有命令都转到 那扇窗户。选择主窗口 同样,使用null作为目标

Window locators provide different ways of specifying the window object:
通过标题,通过内部JavaScript “name”或JavaScript变量

    * title=My Special Window: Finds the window using the text that
显示在标题栏中。小心; 两个窗口可以共享同一标题。 如果发生这种情况,该定位器将 就挑一个吧。 *name=myWindow:使用内部JavaScript查找窗口 “名称”属性。这是第二次 参数“windowName”传递给 JavaScript方法窗口。打开(url, windowName、windowFeatures、, replaceFlag)(哪种硒 拦截)。 *var=variableName:某些弹出窗口未命名 (匿名),但与 中的JavaScript变量名 当前应用程序窗口,例如。 “window.foo=window.open(url);”。在里面 那些箱子,你可以打开窗户 使用“var=foo”

意思是这样的:

1.) if windowID is null, (or the string "null") then it is assumed the
用户指的是原文 窗口(由浏览器实例化)

当前应用程序中的名称 窗口,则假定 变量包含返回值 从对JavaScript的调用 open()方法

“名称”窗口中的名称

试图找到合适的 “标题”。因为“标题”不是 必然是独一无二的,这可能有 意外的行为

If you're having trouble figuring out the name of a window that you want
要进行操作,请查看Selenium 记录标识名称的消息 通过window.open创建的窗口数 (因此被 硒)。您将看到如下消息 以下内容适用于每个窗口的现状 打开:

debug: window.open call intercepted; window ID (which you can
与selectWindow()一起使用是 “myNewWindow”

window.open(如果调用发生在 或在“onLoad”事件之前,例如 示例)。(这是bug SEL-339。)在 在这些情况下,您可以强制Selenium 通过使用注意打开窗口的名称 Selenium openWindow命令,使用 空(空白)url,如下所示: openWindow(“,“myFunnyWindow”)

选择窗口(windowID)

选择弹出窗口

如果是弹出窗口,则执行
选择popup | windowId
,然后返回主窗口执行
选择window | null

选择弹出窗口(windowID)
参数:

  • windowID—弹出窗口的标识符,可以具有许多不同的含义
简化了选择弹出窗口的过程(并且不提供selectWindow()已经提供的功能之外的功能)

  • 如果未指定windowID或指定为“null”,则选择第一个非顶部窗口。顶部窗口将由selectWindow()选择,而不提供windowID。当有多个弹出窗口在运行时,不应使用此选项
  • 否则,窗口将按如下顺序查找:
  • 指定给window.open()的窗口的“名称”
  • 一个JavaScript变量,它是对窗口的引用
  • 窗口的标题。这与selectWindow执行的顺序查找相同

您可以使用“storeAttribute”命令存储随机窗口ID(由Selenium IDE生成)。您只需将ID存储在变量中,然后可以使用“selectWindow”命令选择窗口

尝试使用以下方法:

<tr>
   <td>storeAttribute</td>
   <td>link=Help Center@target</td>
   <td>window_ID</td>
</tr>

<tr>
   <td>selectWindow</td>
   <td>${window_ID}</td>
   <td></td>
</tr> 

storeAttribute
链接=帮助Center@target
窗口ID
选择窗口
${window_ID}

尝试使用Selenium Web驱动程序2:

driver.switch_to.window(driver.window_handles.last);

考虑一下:您是否希望删除
target=“\u blank”
属性?对我来说,这是一个解决方案:

getEval
this.page().findElement('link=Facebook').removeAttribute('target'); 

在Selenium IDE中,保持在同一个窗口中有一些优势,因为它不支持目标空白。

此处报告的错误是否适用于上面概述的内容?我已经和selectWindow搏斗了几个小时了。让我抓狂。另外,别忘了在“selectPopup”之前放置一个“waitForPopUp”,以确保在您尝试选择它之前,弹出窗口已经完成加载。查看此链接,我也在下面发布了,我觉得selectWindow很糟糕:看起来我是无意中否决了它——这个解决方案非常优雅,我希望能够改进到upvoteThis实际上是大多数用例中最快、最简单的解决方案。也适用于表单!
If you're having trouble figuring out the name of a window that you want
debug: window.open call intercepted; window ID (which you can
In some cases, Selenium will be unable to intercept a call to
<tr>
   <td>storeAttribute</td>
   <td>link=Help Center@target</td>
   <td>window_ID</td>
</tr>

<tr>
   <td>selectWindow</td>
   <td>${window_ID}</td>
   <td></td>
</tr> 
driver.switch_to.window(driver.window_handles.last);
getEval
this.page().findElement('link=Facebook').removeAttribute('target');