gpt4 book ai didi

javascript - 当应从先前设置的变量打开下一页时,下一页未加载

转载 作者:行者123 更新时间:2023-11-28 00:48:54 25 4
gpt4 key购买 nike

我正在从 href 属性解析出一个 url,但是当我这样做时

casper.thenOpen(url, function() {
this.echo(this.getCurrentUrl());
});

显示空白。

我尝试访问的网页上的链接在新选项卡中打开,使用 casper 测试新选项卡比导航到同一选项卡上的新链接稍微复杂一些(我认为是这样)这就是为什么我在变量中获取链接然后尝试打开它。

我在这里遗漏了什么吗?

代码片段:

var href = '';

casper.then(function() {
this.test.assertExists(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'the element exists');
href = casper.getElementAttribute(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'href');
});

casper.thenOpen(href, function() {
this.echo(getCurrentUrl());
});

因此,当我 echo href 时,它的值与我要导航到的 url 相同。但是 getCurrentUrl 显示 about:blank。此外,URL 在不到一秒的时间内打开,但当我尝试 casper.waitForUrl() 时,它在 5000 毫秒后超时。

最佳答案

Casper 的工作原理是将所有请求推送到堆栈上,然后运行它们。所以当你这样称呼时:

casper.thenOpen(href, function() {
this.echo(getCurrentUrl());
});

href 尚未有机会被定义。我相信以下重构是修复它的一种方法:

casper.then(function() {
casper.open(href,function(){
this.echo("Did it work this time?");
});
});

关于javascript - 当应从先前设置的变量打开下一页时,下一页未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27023916/

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