abbypan
abbypan

Reputation: 158

how to fill an input field with keydown/keyup/keypress with casperjs?

there is an input field bind with keydown/keyup/keypress/blur event, and want to fill some value to this input field with casperjs

<input type="text" class="some-input" id="somekey" 
onblur="somefunc_1();" 
onkeydown="if(event.keyCode==13)  somefunc_2();"
onkeyup="somefunc_3();" onkeypress="return somefunc_4();">

this is what i try with casperjs, but it's no work:

var somevalue = '3';
casper.then(function(){
        this.mouseEvent( 'click', '#somekey');
        this.page.sendEvent('keypress', somevalue);
        });

casper.wait(1000, function(){
        console.log("input value :" + 
        this.getElementAttribute('#somekey', 'value')); 
        });

Upvotes: 0

Views: 1672

Answers (1)

Joey Guerra
Joey Guerra

Reputation: 596

getElementAttribute is not going to get the value. After playing around with some code, I came up with this which seems to work.

    casper.then(function(){
    this.sendKeys('#somekey', 'just testing this');
    test.comment(this.evaluate(function(){
        return __utils__.getFieldValue('nameOfSomeKeyField');
    }));        
});

Upvotes: 1

Related Questions