简体   繁体   English

在Steam上登录-CasperJS

[英]Logging in on Steam - CasperJS

I want to login on Steam with CasperJS, but it just dont want to work. 我想用CasperJS登录Steam,但它只是不想工作。

This is my code: 这是我的代码:

var url = 'https://steamcommunity.com/login/';

casper.start(url, function() {
    console.log("page loaded");


casper.waitForSelector("form input[name='username']", function() {
}, true);   
    this.fill('form[name="logon"]', { 
        username: 'username', 
        password:  'password'
    }, true);
    this.click('form input#SteamLogin');
});

After executing this code, CasperJS said: 执行此代码后,CasperJS说:

[info] [remote] submitting form to #, HTTP POST
[warning] [remote] unable to submit form

I also used the function "StartLogin" (i found the function in the sourcecode of steam) and executed it with this: 我还使用了“ StartLogin”功能(我在steam的源代码中找到了该功能)并执行以下命令:

casper.evaluate(function(){
    StartLogin();
});

But CasperJS came up with this error: 但是CasperJS想到了这个错误:

Page Error: ReferenceError: Can't find variable: StartLogin

Would be very thankful, if someone could help me :) 如果有人可以帮助我,将非常感激:)

Your problem is quite vague, but I am trying to help 您的问题很模糊,但我正在尝试提供帮助

You have to know the difference between the casper.evaluate and the classic assert statement, I think you mixed something up there 您必须知道casper.evaluate和经典assert语句之间的casper.evaluate ,我认为您在其中混了一些东西

casper.evaluate evaluates a specific statement in the context of phatom, it doesnt evaluate any functions. casper.evaluate在phatom上下文中评估特定语句,不评估任何功能。 If you want to evaluate the proper return of a function use it like this: 如果要评估函数的正确return ,请按以下方式使用它:

var val = casper.evaluate(function() {if(true) return 'foo';});
test.assertEquals(val,'foo');

I hope I could help you a little bit, for further infos look at: 希望对您有所帮助,有关更多信息,请参阅:

  1. CasperJS evaluate CasperJS评估
  2. Tester module casper 测试器模块卡斯珀
  3. CasperJS Plugin for Chrome 适用于Chrome的CasperJS插件

In the fill function you are setting the submit bool to true so the form is being submitted after the username and password are filled out. 在填充功能中,您将Submit bool设置为true,以便在填写用户名和密码后提交表单。

Take out the this.click , then add casper.then(function(){}) to the end to execute your next command. 取出this.click ,然后在最后添加casper.then(function(){})以执行您的下一个命令。

Basically you are trying to click a button that is not there because you have already moved on to the next page by submitting your form. 基本上,您试图单击一个不存在的按钮,因为您已经通过提交表单进入了下一页。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM