Get Window Handles - WebDriver 编辑
The Get Window Handles command of the WebDriver API returns a list of all WebWindow
s. Each tab or window, depending on whether you are using a tabbed browser, is associated by a window handle that is used as a reference when switching to the window.
In order to determine whether or not a particular interaction with the browser opens a new window, one can obtain the set of window handles before the interaction is performed and compare it with the set after the action is performed.
Syntax
Method | URI template |
---|---|
GET | /session/{session id}/window/handles |
URL parameters
session id
- Identifier of the session.
Errors
- Invalid session ID
- Session does not exist.
Example
C#:
using System.Collections.ObjectModel;
using OpenQA.Selenium.Firefox;
namespace MDNWebDriverExamples
{
class Example
{
public static void Main(string[] args)
{
FirefoxDriver session = new FirefoxDriver();
session.ExecuteScript("window.open()");
ReadOnlyCollection<string> currentWindowHandles = session.WindowHandles;
}
}
}
Specifications
Specification | Status | Comment |
---|---|---|
WebDriver The definition of 'Get Window Handles' in that specification. | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
- Switch To Window command
- Get Window Handle command
- Close Window command
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论