无法使用Protractor在Safari浏览器中将焦点切换到子窗口

问题描述 投票:0回答:1

无法在Safari浏览器版本11和12中将焦点切换到子窗口

操作系统版本:macOS High Sierra和macOS Mojave

以下是我尝试过的代码段。

exports.switchWindowFocus = function (url) {

    var self = this;

     browser.getAllWindowHandles().then(function (handles) {

        browser.wait(self.windowCount(2), 10000);

         browser.switchTo().window(handles[1]).then(function(){

             expect(browser.getCurrentUrl()).toEqual(url);
         })
    });
};

仍然关注主窗口而不是切换到子窗口。

有人可以帮我这个吗?

javascript safari protractor
1个回答
0
投票

我很惊讶地看到browser.wait(self.windowCount(2))里面的browser.getAllWindowHandles()。如果你得到了所有的把手而它还没有,那么等待它之后就不会有太大的好处。此外,browser.wait应该承诺与后来的任何东西链接。也许像(未经测试):

exports.switchWindowFocus = function (url) {
  var self = this;
  browser.wait(self.windowCount(2), 10000).then(function() {
    browser.getAllWindowHandles().then(function (handles) {
      console.log(handles.length);
      browser.switchTo().window(handles[1]).then(function() {
        expect(browser.getCurrentUrl()).toEqual(url);
      })
    });
  });
};
© www.soinside.com 2019 - 2024. All rights reserved.