selenium - 你如何专注于 selenium ide 的新窗口?

标签 selenium automated-tests selenium-ide

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

最佳答案

选择窗口

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

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").



选择窗口(窗口ID)

选择弹出

如果它是一个弹出窗口,那么做 selectPopUp | windowId然后回到主窗口做 selectWindow | nullselectPopUp(windowID)参数:
  • windowID - 弹出窗口的标识符,可以具有多种不同的含义

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

    关于selenium - 你如何专注于 selenium ide 的新窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3859233/

    相关文章:

    javascript - 测试未遵守 "beforeEach"内的超时

    node.js - Cypress 永远不会超过 Ubuntu 上的加载屏幕

    selenium - 为什么我们使用 WebDriver 而不是 Selenium IDE?

    .net - 从 Selenium WebDriver 运行 chrome 扩展

    java - 如果它不能为空,但需要初始化,我该怎么办?

    java - Firefox 驱动程序无法检测到 webelement

    web-services - 我的测试自动化策略听起来可笑吗?

    python - 无论如何,是否可以在没有显示器的情况下运行机器人框架测试?

    java - Selenium 设置速度执行测试

    javascript - Selenium - 检查变量内的字符