Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

javascript - Impossible to .sendKeys(..) with CasperJS on some sites

I am loosing my mind over trying to do something inherently seemingly banal, but it seems almost hopeless. For a thesis project I need to collect flight prices. This code should just fill in "zurich" to the departure box. But it doesn't. This code works normally with any text imput box, but on this simple page its hopeless. I really would appreciate someones wisdom here:

// variables
var casper = require("casper").create();
var x      = require('casper').selectXPath;
var url    = 'http://www.statravel.ch';

var depart_box_x = '//*[@id="qbtb_2_0_id_0"]/div/div[1]/div[2]/div[2]/form/fieldset[2]/div[1]/p/input';

// init casper
casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
casper.start(url);

// run through page
casper.then(function() {
    this.click(x(depart_box_x));
    this.sendKeys(x(depart_box_x), 'ZURICH', { reset: true} );
    console.log('sending keys...');
});

casper.then(function() {
    console.log('screenshot...');
    casper.capture('cap.png');
});

// run command for casperjs
casper.run();

If you look at the screenshot, the field is blank. But no errors pop up. If you do the same but instead of the departure box you select the email box at the top of the page, it fills it in. It feels like they on purpose made this impossible.

Thank you for any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...