正在尝试获取CurrentUrl()并在量角器的新选项卡中打开它



我必须获取url并在3个新选项卡中打开它。但我在尝试时出错:

browser.getCurrentUrl().then(url => {
browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('t').perform();
browser.sleep(2000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows  //  // 
browser.get(url)

});
});

错误:Failed: null value in entry: name=null

这些都是chrome驱动程序在浏览器级别模拟相同行为的限制。这意味着sendKeys无法在您尝试代码时打开新选项卡。有另一种方法可以通过'window.open(('来实现您的目标。这是您的代码片段,只需进行少量修改。希望这对你有所帮助。

browser.getCurrentUrl().then(url => {
browser.executeScript('window.open()').then( () => {
browser.sleep(2000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows  //  // 
browser.get(url);
});
});
});

相关内容

最新更新