如何使用 selenium ide 专注于新窗口?

发布于 2024-09-26 01:41:40 字数 90 浏览 6 评论 0原文

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

I am trying to use selenium ide to duplicate an action. The action is clicking on a link that open a new window. How do you make selenium ide focus on the new window instead of the other one? It has not been working for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆伤 2024-10-03 01:41:41

选择窗口

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

要从其他窗口返回主窗口,请执行 selectWindow |空

参数:

    * windowID - 要选择的窗口的 JavaScript 窗口 ID

使用窗口定位器选择弹出窗口;一旦弹出窗口

已被选择,所有命令都转到
那个窗户。选择主窗口
再次使用 null 作为目标。

窗口定位器提供了指定窗口对象的不同方式:

按标题,通过内部 JavaScript
“名称”,或通过 JavaScript 变量。

 * title=我的特殊窗口:使用以下文本查找窗口

出现在标题栏中。当心;
两个窗口可以共享相同的标题。
如果发生这种情况,该定位器将
就选一个吧。
* name=myWindow:使用其内部 JavaScript 查找窗口
“名称”属性。这是第二个
参数“windowName”传递给
JavaScript 方法 window.open(url,
窗口名称、窗口功能、
ReplaceFlag)(其中 Selenium
拦截)。
* var=variableName: 部分弹窗未命名
(匿名),但与
JavaScript 中的变量名
当前应用程序窗口,例如
“window.foo = window.open(url);”。在
这些情况,你可以打开窗户
使用“var=foo”。

如果没有提供窗口定位器前缀,我们将尝试猜测您的内容

意思是这样的:

1.) 如果 windowID 为 null(或字符串“null”),则假定

用户指的是原文
由浏览器实例化的窗口)。

2.) 如果“windowID”参数的值是 JavaScript 变量

当前应用程序中的名称
窗口,那么假设这个
变量包含返回值
从对 JavaScript 的调用
window.open() 方法。

3.) 否则,selenium 会查找它维护的映射字符串的哈希值

名称到窗口“名称”。

4.) 如果失败,我们将尝试循环所有已知的窗口

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

如果您无法确定所需窗口的名称

要操作,请查看 Selenium
识别名称的日志消息
通过 window.open 创建的窗口数量
(因此被拦截
硒)。您会看到类似的消息
每个窗口如下
打开:

debug: window.open 调用被拦截;窗口 ID(您可以

与 selectWindow() 一起使用是
“我的新窗口”

在某些情况下,Selenium 将无法拦截对

window.open(如果调用发生在
或在“onLoad”事件之前,对于
例子)。 (这是错误 SEL-339。)
在这些情况下,你可以强制 Selenium
使用以下命令注意打开的窗口的名称
Selenium openWindow 命令,使用
一个空的(空白)网址,如下所示:
openWindow("", "myFunnyWindow").

selectWindow(windowID)

selectPopup

如果它是弹出窗口,则执行 selectPopUp | windowId 然后返回主窗口执行 selectWindow | null

selectPopUp(windowID) 参数:

  • windowID - 弹出窗口的标识符,可以有多种不同的含义

简化选择弹出窗口的过程(并且不提供功能)超出 selectWindow() 已经提供的功能)。

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

Select Window

For this you will need to use the selectWindow | windowName command.

To go back to the main window from the other window then do 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

has been selected, all commands go to
that window. To select the main window
again, use null as the target.

Window locators provide different ways of specifying the window object:

by title, by internal JavaScript
"name," or by JavaScript variable.

    * title=My Special Window: Finds the window using the text that

appears in the title bar. Be careful;
two windows can share the same title.
If that happens, this locator will
just pick one.
* name=myWindow: Finds the window using its internal JavaScript
"name" property. This is the second
parameter "windowName" passed to the
JavaScript method window.open(url,
windowName, windowFeatures,
replaceFlag) (which Selenium
intercepts).
* var=variableName: Some pop-up windows are unnamed
(anonymous), but are associated with a
JavaScript variable name in the
current application window, e.g.
"window.foo = window.open(url);". In
those cases, you can open the window
using "var=foo".

If no window locator prefix is provided, we'll try to guess what you

mean like this:

1.) if windowID is null, (or the string "null") then it is assumed the

user is referring to the original
window instantiated by the browser).

2.) if the value of the "windowID" parameter is a JavaScript variable

name in the current application
window, then it is assumed that this
variable contains the return value
from a call to the JavaScript
window.open() method.

3.) Otherwise, selenium looks in a hash it maintains that maps string

names to window "names".

4.) If that fails, we'll try looping over all of the known windows

to try to find the appropriate
"title". Since "title" is not
necessarily unique, this may have
unexpected behavior.

If you're having trouble figuring out the name of a window that you want

to manipulate, look at the Selenium
log messages which identify the names
of windows created via window.open
(and therefore intercepted by
Selenium). You will see messages like
the following for each window as it is
opened:

debug: window.open call intercepted; window ID (which you can

use with selectWindow()) is
"myNewWindow"

In some cases, Selenium will be unable to intercept a call to

window.open (if the call occurs during
or before the "onLoad" event, for
example). (This is bug SEL-339.) In
those cases, you can force Selenium to
notice the open window's name by using
the Selenium openWindow command, using
an empty (blank) url, like this:
openWindow("", "myFunnyWindow").

selectWindow(windowID)

selectPopup

If it is a popup then do selectPopUp | windowId and then to go back to the main window do selectWindow | null

selectPopUp(windowID) Arguments:

  • windowID - an identifier for the popup window, which can take on a number of different meanings

Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).

  • If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play.
  • Otherwise, the window will be looked up considering windowID as the following in order:
    1. The "name" of the window, as specified to window.open()
    2. A JavaScript variable which is a reference to a window
    3. The title of the window. This is the same ordered lookup performed by selectWindow
半暖夏伤 2024-10-03 01:41:41

使用 Selenium Web Driver 2 尝试一下:

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

Try this using Selenium Web Driver 2:

driver.switch_to.window(driver.window_handles.last);
多情癖 2024-10-03 01:41:41

您可以使用“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> 

You can store the random window ID (generated by Selenium IDE) using ‘storeAttribute’ command. You just need to store the ID in a variable and then you can select the window using ‘selectWindow’ command.

Try using this:

<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> 
初雪 2024-10-03 01:41:41

考虑一下:您是否愿意仅删除 target="_blank" 属性?对我来说,这是一个解决方案:

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

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

Consider this: would you prefer to just remove the target="_blank" attribute? For me this has been a solution:

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

Staying within the same window has some advantages in Selenium IDE, seeing it doesn't support target blank.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文