Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var casper = require('casper').create({
- verbose: true,
- //logLevel: 'debug',
- pageSettings: {
- loadImages: false, // The WebPage instance used by Casper will
- loadPlugins: false, // use these settings
- userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
- }
- });
- casper.options.waitTimeout = 40000
- casper.options.viewportSize = {width: 1680, height: 949};
- casper.on("remote.message", function(msg) {
- this.echo("Console: " + msg);
- });
- // http://docs.casperjs.org/en/latest/events-filters.html#page-error
- casper.on("page.error", function(msg, trace) {
- this.echo("Error: " + msg);
- // maybe make it a little fancier with the code from the PhantomJS equivalent
- });
- // http://docs.casperjs.org/en/latest/events-filters.html#resource-error
- casper.on("resource.error", function(resourceError) {
- this.echo("ResourceError: " + JSON.stringify(resourceError, undefined, 4));
- });
- // http://docs.casperjs.org/en/latest/events-filters.html#page-initialized
- casper.on("page.initialized", function(page) {
- // CasperJS doesn't provide `onResourceTimeout`, so it must be set through
- // the PhantomJS means. This is only possible when the page is initialized
- page.onResourceTimeout = function(request) {
- console.log('Response Timeout (#' + request.id + '): ' + JSON.stringify(request));
- };
- });
- retryOpen = function(){
- this.thenOpen("https://www.example.com", function(response){
- var httpstatus = response.status;
- if(httpstatus != 200){
- this.echo("FAILED GET WEBSITE, RETRY");
- this.then(retryOpen);
- } else{
- this.waitFor(function check() {
- return this.evaluate(function() { //HÄR JUST
- return document.querySelectorAll('#id1').length > 0;
- });//
- }, function then() {
- this.waitFor(function check() {
- return this.evaluate(function() { //HÄR JUST
- return document.querySelectorAll('#my-select').length > 0;
- });//
- }, function then() {
- this.fillSelectors('#my-select', {
- 'input[id="id1"]': "dummydata"
- }, false);
- //Here seems the error to be, this.click button:
- this.click("button.submit.id_submit");
- this.then(nextfunction); //var grabYear
- },function timeout() { // step to execute if check has failed
- this.echo("TimeOut1").exit();
- });
- },function timeout() { // step to execute if check has failed
- this.echo("TimeOut2").exit();
- });
- }
- });
- }
Add Comment
Please, Sign In to add comment