Phantomjs 看不到 Twitter/Facebook 授权页面

Phantomjs does not see twitter/facebook authorization page

本文关键字:授权 Facebook 看不到 Twitter Phantomjs      更新时间:2023-09-26

我正在测试从我们的网站添加Twitter/Facebook帐户功能。从我的网站单击"连接到推特"按钮时,我们被重定向(使用 oauth 进行验证和授权)到 推特 API 以授予访问权限等。从我的 casper 测试模块中,单击"连接到 twitter"按钮后,我从屏幕截图中看到 phantomjs 仍然存在于我当前的网站页面上,并且没有转到实际的 Twitter api 页面。有人可以在这里帮助我吗?

脚本片段:

exports.addAccount = function(options) {
    this.navToAddService(); //custom function to navigate to particular page
    casper.then(function() {
        this.click('#add_twitter'); //this is the id of the button 'connect to twitter'
    }).then(function() {
        this.echo(this.getCurrentUrl());
    });
};

在尝试单击按钮之前,如何更改代码以使用waitForSelector()

exports.addAccount = function(options) {
    this.navToAddService(); //custom function to navigate to particular page
    casper.waitForSelector('#add_twitter', function() {
        this.click('#add_twitter'); //this is the id of the button 'connect to twitter'
    }).then(function() {
        this.echo(this.getCurrentUrl());
    });
};

这绕过了异步代码的任何潜在计时问题。(例如,我猜navToAddService()正在添加您尝试单击的按钮。

如果超时,

您就知道该按钮永远不会出现,并且可以开始对更具体的问题进行故障排除。

同样,您可以使用waitForUrl()而不是使用then() 与所需 URL 的名称一起使用。