如何确定Webdriver中已加载的其他页面

时间:2017-03-29 08:32:58

标签: selenium-webdriver webdriver webdriver-io

我有两个页面如下:

第一页:

<!DOCTYPE html>
<html>
<head>
    <title>First Page</title>
</head>
<body>
    <h1 class="page-info">This is first page</h1>
    <a class="link-line" href="/second_page/">Go to second page</a>
</body>
</html>

第二页:

<!DOCTYPE html>
<html>
<head>
    <title>Second Page</title>
</head>
<body>
    <h1 class="page-info">This is second page</h1>
    <a class="link-line" href="/first_page/">Back to first page</a>
</body>
</html>

在我点击 标记的第一页中,浏览器将加载第二页。如何确定第二页已经加载完毕。

我试过

describe("Test Load New Page", () => {
    it("should load second page", () => {
        browser.url('/first_page/');

        const pageInfoSelector1 = ".page-info";
        browser.waitForVisible(pageInfoSelector1);

        const pageInfo1 = browser.getText(pageInfoSelector1);
        assert.equal(pageInfo1, "This is first page");

        const aTag = ".link-line";
        browser.waitForEnabled(aTag);
        browser.click(aTag);

        const pageInfoSelector2 = ".page-info";
        browser.waitForVisible(pageInfoSelector2); 

        const pageInfo2 = browser.getText(pageInfoSelector2);
        assert.equal(pageInfo2, "This is second page"); // Error here: AssertError: Can not assert "This is first page" == "This is second page"
    });
});

错误:AssertError: Can not assert "This is first page" == "This is second page"

这意味着const pageInfo2 = browser.getText(pageInfoSelector2);在第一页而不是第二页中有 h1 标记的文字。

有人可以帮忙吗?提前谢谢!

0 个答案:

没有答案
相关问题