简体   繁体   English

如何使用量角器获取新的打开的标签URL

[英]Howto get new opened tab URL with protractor

Hi I'm trying to get the url from a new tab opened after click on a link, and check if I get the expected value. 嗨,我正在尝试通过单击链接后从打开的新选项卡获取url,并检查是否获得了期望的值。 I can't figure out how to do it because I get this error on the chrome execution: 我不知道该怎么做,因为在chrome执行过程中出现此错误:

Failed: null value in entry: name=null

In Firefox the test passes, but the funny part is that it opens a target=_blank in a new window instead of a new tab... 在Firefox中,测试通过了,但有趣的是,它在新窗口而不是新标签页中打开了target = _blank ...

Here is my code: 这是我的代码:

var scrollBar = require("./lib/scroll_bar");

describe("WAM home blog tests", function() {

    var URL = 'http://dev.wam.com.es';

    beforeEach(function() {
        browser.driver.manage().window().maximize();
        browser.get(URL);
    });

    it("Should find blog section after scrolling", function() {
        scrollBar.doScroll(0, 1800);
        expect( $("#blog-panel").isPresent() ).toBe(true);
    });

    it("Should redirect to blog after click on link", function() {
        var EC = protractor.ExpectedConditions;

        scrollBar.doScroll(0, 1800);
        element.all( by.css('div.blog-post > a') ).first().click();

        browser.ignoreSynchronization = true;
        browser.getAllWindowHandles().then(function (handles) {
            console.log(handles);
            browser.switchTo().window(handles[1]);
            var header = element(by.id("header"));
            browser.wait(EC.visibilityOf(header), 15000);
            expect(browser.driver.getCurrentUrl())
                .toMatch(/^http:\/\/blog.wam.tv\/.*/);
            browser.driver.close();
            browser.driver.switchTo().window(handles[0]);
        });
    });

    afterEach(function() {
        browser.ignoreSynchronization = false;
    });

});

What you can do is to open the link in a new browser window by making a SHIFT+click: 您可以做的是通过按SHIFT键并单击来在新的浏览器窗口中打开链接:

var elm = element.all( by.css('div.blog-post > a') ).first();
browser.actions().mouseMove(elm).keyDown(protractor.Key.SHIFT).click().keyUp(protractor.Key.SHIFT).perform();

This helped me before in a similar situation. 这在类似情况下对我有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 等待量角器加载在新选项卡中打开的数据 - Wait for protractor to load data opened in new tab new url 不在新标签页打开 - New url is not opened in a new tab 如果手动单击 URL 并打开一个新选项卡,那么打开的选项卡是否可以获取对单击 URL 的窗口的引用? - If an URL is clicked manually and opens a new tab, is there anyway for the opened tab to get a reference to the window where the URL was clicked? 如何获取当前打开的标签页的URL? - How to get the url of the tab that is currently opened? 在新标签页中获取引荐网址 - Get referral Url in new tab Puppeteer 检测新标签页何时打开并获取页面对象 - Puppeteer detect when the new tab is opened and get page object 在现有的以编程方式打开的新窗口(Firefox)中,在“新标签”中打开URL无效 - Opening URL in New Tab doesn't work in existing, programmatically-opened New Window (Firefox) 从量角器中的标签获取元素 - Get element from tab in protractor 单击后打开新页面时获得其URL - get the url of a new page when it is opened after click 与_blank的常规链接在选项卡中打开,但是JS window.open(url,“_ blank”); 打开一个新窗口? - A regular link with _blank gets opened in tab but a JS window.open(url, “_blank”); open a new window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM