你如何专注于使用 selenium ide 的新窗口? [英] How do you focus on new windows with selenium ide?

查看:20
本文介绍了你如何专注于使用 selenium ide 的新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 selenium ide 来复制一个动作.该操作是单击打开新窗口的链接.你如何让 selenium ide 专注于新窗口而不是另一个?它对我不起作用.

解决方案

选择窗口

为此,您需要使用 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").

选择窗口(窗口ID)

选择弹出窗口

如果是弹出窗口,则执行 selectPopUp |windowId 然后回到主窗口做 selectWindow |空

selectPopUp(windowID) 参数:

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

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

  • 如果没有指定windowID,或者指定为null",则选择第一个非顶部窗口.顶部窗口是 selectWindow() 在不提供 windowID 的情况下选择的窗口.在播放多个弹出窗口时不应使用此选项.
  • 否则,将按照以下顺序查找窗口,并考虑 windowID:

    1. 窗口的名称",由 window.open() 指定
    2. 作为对窗口的引用的 JavaScript 变量
    3. 窗口的标题.这与 selectWindow 执行的有序查找相同

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.

解决方案

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

这篇关于你如何专注于使用 selenium ide 的新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆