NodeJS 获取浏览器的当前URL

inkz8wg9  于 2023-03-29  发布在  Node.js
关注(0)|答案(3)|浏览(250)

在Selenium Nodejs中,我如何获得我正在测试的页面的当前URL(当我的测试脚本运行时,假设页面最初已被重定向)

gcuhipw9

gcuhipw91#

driver.get("http://www.google.com")
    .then(function() {
        return driver.getCurrentUrl();
    })
    .then(function(currentUrl) {
        // work with the current url of browser
    });
bnl4lu3b

bnl4lu3b2#

print(api.driver.getCurrentUrl().toString())
bq3bfh9z

bq3bfh9z3#

要显示,必须使用toString:

var currentURL = driver.getCurrentUrl().toString();
console.log("***>>> getCurrentUrl: "+currentURL);

相关问题