gpt4 book ai didi

javascript - 获取点击后打开新页面的url

转载 作者:行者123 更新时间:2023-12-03 08:41:24 26 4
gpt4 key购买 nike

我正在编写一个测试,单击按钮并打开一个新选项卡并将您定向到一个新网站。我想调用该网站值,以便我可以在网页名称中的 rfp 代码之后解析它。然后,我打开一个解码器站点并使用它进行解码并确保解码后的网页名称正常工作。

我正在使用的代码:

this.switchesToGetQuotePage = function() {
browser.getAllWindowHandles().then(function(handles) {
newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function() {
getCurrentUrl.then(function(text) {
console.log(text);
});
});
});
};

当我调用 getCurrentUrl 函数时,它返回以下值:

data: ,

最佳答案

使用 getLocationAbsUrl() 中内置的 Protractor 来获取当前页面的 url(如果基于 Angular )。方法如下 -

browser.getLocationAbsUrl().then(function(url){
console.log(url);
});

但是,如果您正在处理非 Angular 页面,请等到页面随着 url 更改(通过重定向)而加载,直到最终页面交付给客户端,然后使用 getCurrentUrl()在页面上。方法如下 -

   var ele = $("ELEMENT_ON_NEW_PAGE"); //replace it with your element on the page
browser.switchTo().window(newWindowHandle).then(function() {
browser.wait(protractor.ExpectedConditions.visibilityOf(ele), 10000).then(function(){
getCurrentUrl.then(function(text) {
console.log(text);
});
});
});

希望有帮助。

关于javascript - 获取点击后打开新页面的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33042005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com