【问题标题】:TypeError when calling sendKeys in CasperJS在 CasperJS 中调用 sendKeys 时出现 TypeError
【发布时间】:2012-12-15 18:04:28
【问题描述】:

我正在尝试使用 coffeescript 和 casperjs (1.0.0-RC4) 完成繁琐的登录,并希望填写一个使用 name 属性作为其字段的表单(例如<input type='text' name='accountname'></input>)。我最初打算使用@fill 来完成表单,但是由于 id 属性不在输入标签中,所以遇到了问题(我猜)。所以,我决定使用@sendKeys 方法,但它抛出了一个非常令人困惑的错误:

TypeError: 'undefined' is not a function (evaluating 'this.sendKeys('#accountname', developerAccountName)')

在这段代码 sn-p 中有什么明显的我做错了吗:

#!/usr/bin/env casperjs

developerAccountName = "user@user.com"
developerPassword = "password"

casper = require("casper").create(
    verbose: true
    logLevel: "debug"
    );

casper.start "http://www.example.com"

casper.thenClick "#content .maincontent .image.first a"

casper.thenClick ".button.blue"

casper.then ->
    if (@exists "#accountname") and (@exists "#accountpassword")
        @sendKeys '#accountname', developerAccountName
        @sendKeys '#accountpassword', developerPassword
        @click "form .signin-button"
    else
        @echo "Couldn't find the fields"

casper.run ->
    @echo "Complete."

【问题讨论】:

  • 嘿@muistooshort - 我试了一下,现在的错误是_this 没有方法。 TypeError: 'undefined' is not a function (evaluating '_this.exists("#accountname")')
  • 这已解决 - 他们在 1.0.0.RC5 中将 sendKeys 添加到 CasperJS。

标签: coffeescript casperjs


【解决方案1】:

sendKeys 方法直到 1.0.0.RC5 才可用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    相关资源
    最近更新 更多