我正在尝试使用 selenium ide 来复制一个动作。该操作是单击打开新窗口的链接。你如何让 selenium ide 专注于新窗口而不是另一个?它对我不起作用。
4 回答
选择窗口
为此,您将需要使用该selectWindow | windowName
命令。
要从另一个窗口返回主窗口,然后执行selectWindow | null
Arguments: * windowID - the JavaScript window ID of the window to select Selects a popup window using a window locator; once a popup window
已被选中,所有命令都转到该窗口。要再次选择主窗口,请使用 null 作为目标。
Window locators provide different ways of specifying the window object:
按标题、按内部 JavaScript“名称”或按 JavaScript 变量。
* title=My Special Window: Finds the window using the text that
出现在标题栏中。当心; 两个窗口可以共享相同的标题。如果发生这种情况,这个定位器只会选择一个。* name=myWindow:使用其内部 JavaScript“名称”属性查找窗口。这是传递给 JavaScript 方法 window.open(url, windowName, windowFeatures, replaceFlag) (Selenium 拦截)的第二个参数“windowName”。* var=variableName:一些弹出窗口未命名(匿名),但与当前应用程序窗口中的 JavaScript 变量名相关联,例如“window.foo = window.open(url);”。在这些情况下,您可以使用“var=foo”打开窗口。
If no window locator prefix is provided, we'll try to guess what you
意思是这样的:
1.) if windowID is null, (or the string "null") then it is assumed the
用户指的是浏览器实例化的原始窗口)。
2.) if the value of the "windowID" parameter is a JavaScript variable
在当前应用程序窗口中命名,则假定此变量包含调用 JavaScript window.open() 方法的返回值。
3.) Otherwise, selenium looks in a hash it maintains that maps string
名称到窗口“名称”。
4.) If that fails, we'll try looping over all of the known windows
试图找到合适的“标题”。由于“标题”不一定是唯一的,这可能会产生意想不到的行为。
If you're having trouble figuring out the name of a window that you want
要进行操作,请查看 Selenium 日志消息,这些消息标识了通过 window.open 创建的窗口的名称(因此被 Selenium 拦截)。在打开每个窗口时,您将看到如下消息:
debug: window.open call intercepted; window ID (which you can
与 selectWindow()) 一起使用的是“myNewWindow”
In some cases, Selenium will be unable to intercept a call to
window.open(例如,如果调用发生在“onLoad”事件期间或之前)。(这是错误 SEL-339。)在这些情况下,您可以使用 Selenium openWindow 命令强制 Selenium 注意到打开窗口的名称,使用空(空白)url,如下所示: openWindow("", "myFunnyWindow") .
选择窗口(窗口 ID)
选择弹出
如果是弹出窗口然后执行selectPopUp | windowId
然后返回主窗口执行selectWindow | null
selectPopUp(windowID)
论据:
- windowID - 弹出窗口的标识符,它可以具有多种不同的含义
简化了选择弹出窗口的过程(并且不提供超出 selectWindow() 已经提供的功能)。
- 如果未指定 windowID 或指定为“null”,则选择第一个非顶部窗口。顶部窗口是 selectWindow() 在不提供 windowID 的情况下选择的窗口。在播放多个弹出窗口时不应使用此选项。
- 否则,将按照以下顺序查找窗口,并考虑 windowID:
- 窗口的“名称”,由 window.open() 指定
- 一个 JavaScript 变量,它是对窗口的引用
- 窗口的标题。这与 selectWindow 执行的有序查找相同
使用 Selenium Web Driver 2 试试这个:
driver.switch_to.window(driver.window_handles.last);
您可以使用“<strong>storeAttribute”命令存储随机窗口 ID(由 Selenium IDE 生成)。您只需要将 ID 存储在变量中,然后您可以使用“<strong>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>
考虑一下:您是否愿意只删除该target="_blank"
属性?对我来说,这是一个解决方案:
getEval
this.page().findElement('link=Facebook').removeAttribute('target');
在 Selenium IDE 中保持在同一窗口内有一些优势,因为它不支持目标空白。