【问题标题】:Get list of Chrome Windows (OS-Level)获取 Chrome Windows 列表(操作系统级别)
【发布时间】:2021-12-03 04:50:27
【问题描述】:

我最初认为我可以通过以下方式检索 Chrome Windows:

browser.getWindowHandles()

问题在于它实际上并没有获得 Chrome“窗口”而是标签。 Selenium 中是否有真正的“视觉”Chrome 窗口的概念?我想知道一个选项卡是否来自一个特定的窗口,以及一个窗口中有多少个选项卡。该文档具有误导性,尤其是 getAllWindowHandles,这意味着它与 Window 有关。

我基本上是在寻找获取“OS Window”及其选项卡的解决方案。我已经从 Selenium 切换到 WebdriverIO 可能认为这是可能的,但我在文档中找不到。

感谢大家的帮助!

【问题讨论】:

    标签: webdriver-io


    【解决方案1】:

    https://stackoverflow.com/a/34655248/6793637

    Windows 和 Tabs 类似,取决于浏览器设置是否应该在选项卡或窗口中打开新链接。

    如果您打开一个新窗口或标签,两者都会在 selenium/wdio 中被检测到。请注意,选项卡或窗口计数适用于 selenium 会话打开的窗口,而不是系统中打开的整个窗口

    例如

    it('should login with valid credentials', async () => {
        await LoginPage.open();
        // opens new tab
        await browser.execute((a) => { window.open(a) }, 'http://the-internet.herokuapp.com/login')
        await expect((await browser.getWindowHandles()).length).toBe(2);
        //opens new window
        await browser.execute((a) => { window.open(a, 'target', 'features') }, 'http://the-internet.herokuapp.com/login')
        await expect((await browser.getWindowHandles()).length).toBe(3);
        await browser.pause(5000);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      • 2012-09-11
      • 1970-01-01
      • 2012-08-26
      • 2021-03-05
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多