【问题标题】:How do I make sure that a new window has opened in my protractor test如何确保在量角器测试中打开了一个新窗口
【发布时间】:2019-10-22 01:11:36
【问题描述】:

我正在尝试弄清楚如何检查新窗口是否已打开以及 URL 是否正确

每次我尝试检查是否打开了一个新窗口时,测试就会超时,因为我不知道如何切换标签

有没有办法点击打开新标签的按钮并检查网址是否正确?

【问题讨论】:

    标签: selenium selenium-webdriver jasmine protractor


    【解决方案1】:

    在 Selenium 中,您需要在打开新选项卡时切换到正确的窗口句柄,然后才能对其执行任何功能。您需要执行一些额外的代码来获取窗口句柄,并像这样切换到新打开的句柄:

    // save parent window handle in case you need to switch back to it
    var parentWindow=handles[0];
    
    // switch to 2nd opened window, perform a function on it
    driver.getAllWindowHandles().then(function(handles){
        driver.switchTo().window(handles[1]).then(function(){
            // verify the correct URL here
        });
    });
    
    // switch back to parent
    driver.switchTo().window(parentWindow);
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多