personal web log written by izabeera and dryobates

casperjs tricks

Capture screenshot of the content in the frame

by izabeera

Some time ago I had to scrape some data from site, that have many framesets in the html structure.

It looked like this bellow:

<frameset>
  <frame name=”first”>
    <frame name=”next”>
      <form name=”myForm”>
        ….
      </form>
    </frame>
  </frame>
<frameset>

How to submit form “myForm” by using CasperJS?

First think was: “Don't panic, you can use javascript” :) But I'm very lazy woman ;) and I didn't want to write any javascript's code (even it could be few lines in jQuery). I had made research and I found answer – object Page provided by phantomjs and swichToFrame (http://phantomjs.org/api/webpage/method/switch-to-frame.html) function.

Summarizing, in CasperJS swich to frame will be look like bellow:

casper.start(url);

casper.waitFor(function(){
    return "frame[name=first]";
}, function then(){
    this.page.switchToFrame('first');
    this.wait(10000, function() {
        this.page.switchToFrame('next');
        this.fill('form', {…}, true);
    });
}, function timeout(){
    this.echo('Ohh no :/');
});

casper.run();

izabeera
izabeera
Iza Kartowicz-Stolarska. IT engineer. I work in programming since 2005. During this time I gained wealth of experience in writing web applications... and loved Python and Vim :) I enjoy working with people which have positive attitude to the world. Email: iza@stolarscy.com

Archive

Tag cloud