无法使用 WebdriverIO (Selenium) 切换窗口



目前无法在不同的浏览器选项卡之间切换。

我的测试类中包含的代码:

describe('Validate switching of tabs', () => {
    beforeEach(function() {
        browser.url("https://duckduckgo.com") 
      });
    it('Switch tab', () => {
        browser.newWindow('https://webdriver.io')
        browser.switchToWindow('DuckDuckGo — Privacy, simplified.');
    })
})

似乎收到以下异常:

[0-0] 2019-07-24T10:22:26.116Z ERROR webdriver: Request failed due to Error: no such window
  (Session info: chrome=75.0.3770.142)
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64)
    at getErrorFromResponseBody (C:UsersGianni BrunoDesktopwebdriverio-v5node_moduleswebdriverbuildutils.js:371:10)
    at Request._callback (C:UsersGianni BrunoDesktopwebdriverio-v5node_moduleswebdriverbuildrequest.js:120:64)
    at Request.self.callback (C:UsersGianni BrunoDesktopwebdriverio-v5node_modulesrequestrequest.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at Request.<anonymous> (C:UsersGianni BrunoDesktopwebdriverio-v5node_modulesrequestrequest.js:1161:10)
    at Request.emit (events.js:198:13)
    at Request.EventEmitter.emit (domain.js:448:20)
    at IncomingMessage.<anonymous> (C:UsersGianni BrunoDesktopwebdriverio-v5node_modulesrequestrequest.js:1083:12)
    at Object.onceWrapper (events.js:286:20)
[0-0] Error in "Validate switching of tabs Switch tabs"
no such window
  (Session info: chrome=75.0.3770.142)
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64)

感谢您的帮助。

使用 switchWindow 方法而不是 switchToWindow 方法。在此处阅读更多内容。

describe('Validate switching of tabs', () => {
  beforeEach(function() {
    browser.url("https://duckduckgo.com") 
  });
  it('Switch tab', () => {
    browser.newWindow('https://webdriver.io')
    browser.switchWindow('DuckDuckGo — Privacy, simplified.');
  })
})

尝试使用 browser.switchWindow(urlOrTitleToMatch(

describe('Validate switching of tabs', () => {
beforeEach(function() {
    browser.url("https://duckduckgo.com") 
  });
it('Switch tab', () => {
    browser.newWindow('https://webdriver.io')
    browser.switchWindow('DuckDuckGo — Privacy, simplified.');
})

}(

相关内容

  • 没有找到相关文章

最新更新