我正在写一个测试,点击一个按钮,打开一个新的选项卡,并指导你到一个新的网站。我想调用该网站的值,以便我可以在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: ,
发布于 2015-10-09 17:22:27
使用getLocationAbsUrl()中构建的量角器获取当前页面的url (如果它的角度是基于角的)。以下是如何-
browser.getLocationAbsUrl().then(function(url){
console.log(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);
});
});
});希望能帮上忙。
https://stackoverflow.com/questions/33042005
复制相似问题