javascript - 在casperjs中获取输入值

标签 javascript testing phantomjs casperjs

嗨,我想知道如何使用 casperjs 获取输入值

这是我的html元素

<input type="hidden" name="key" value="newkey">

这是我试过的:

    view            = 'users/registered';

    casper.test.begin("Activating account", 5, function register(test){
        casper.start(webroot + view, function(){

        }).then(function(){
            this.echo("Retrieving data from hidden input key", "COMMENT");

            activationKey = this.evaluate(function() {
                return __utils__.getFieldValue('key');
            });

        }).then(function(){
            this.echo("Activating account with the key \"" + activationKey + "\"", "COMMENT");
            window.location = webroot + activationKey;
        });

        casper.run(function() {
            this.echo('Account activated successfully', 'SUCCESS').exit();
            test.done();
        });
    });

casper.viewport(page.width, page.height);

在这种情况下返回null

我也试过:

activationKey = __utils__.getFieldValue('key');

但是返回这个错误:

FAIL ReferenceError: Can't find variable: __utils__

最佳答案

尝试使用这个:

this.getElementAttribute('input[type="hidden"][name="key"]', 'value');

关于javascript - 在casperjs中获取输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23199489/

相关文章:

javascript - 属性 'cacheLocation' 的类型不兼容

java - 使用WebMvcTest测试具有重复名称的 Controller

javascript - 如何使用 capybara 和恶作剧检查 Javascript 错误?

javascript - 使用 CasperJS 接受 cookie 策略

ruby-on-rails - 如何让poltergeist/PhantomJS延迟将页面返回给Capybara,直到AJAX加载?

javascript - 链接 redux 连接 mapStateToProps ,以访问 mapDispatchToProps 内的 props

javascript - Bootstrap 3 中的 Scrollspy 不起作用

javascript - 在 Javascript 计算中显示 2 位小数的值

testing - 在集成测试期间如何运行服务器(进程)?

android - "Monkey Runner"对测试人员直接在Android应用程序中准备测试用例有用吗?