Guest User

Untitled

a guest
Mar 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. var casper = require('casper').create({
  2. verbose: true,
  3. //logLevel: 'debug',
  4. pageSettings: {
  5. loadImages: false, // The WebPage instance used by Casper will
  6. loadPlugins: false, // use these settings
  7. 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'
  8. }
  9. });
  10. casper.options.waitTimeout = 40000
  11. casper.options.viewportSize = {width: 1680, height: 949};
  12.  
  13. casper.on("remote.message", function(msg) {
  14. this.echo("Console: " + msg);
  15. });
  16.  
  17. // http://docs.casperjs.org/en/latest/events-filters.html#page-error
  18. casper.on("page.error", function(msg, trace) {
  19. this.echo("Error: " + msg);
  20. // maybe make it a little fancier with the code from the PhantomJS equivalent
  21. });
  22.  
  23. // http://docs.casperjs.org/en/latest/events-filters.html#resource-error
  24. casper.on("resource.error", function(resourceError) {
  25. this.echo("ResourceError: " + JSON.stringify(resourceError, undefined, 4));
  26. });
  27.  
  28. // http://docs.casperjs.org/en/latest/events-filters.html#page-initialized
  29. casper.on("page.initialized", function(page) {
  30. // CasperJS doesn't provide `onResourceTimeout`, so it must be set through
  31. // the PhantomJS means. This is only possible when the page is initialized
  32. page.onResourceTimeout = function(request) {
  33. console.log('Response Timeout (#' + request.id + '): ' + JSON.stringify(request));
  34. };
  35. });
  36.  
  37. retryOpen = function(){
  38. this.thenOpen("https://www.example.com", function(response){
  39. var httpstatus = response.status;
  40. if(httpstatus != 200){
  41. this.echo("FAILED GET WEBSITE, RETRY");
  42. this.then(retryOpen);
  43. } else{
  44. this.waitFor(function check() {
  45. return this.evaluate(function() { //HÄR JUST
  46. return document.querySelectorAll('#id1').length > 0;
  47. });//
  48. }, function then() {
  49. this.waitFor(function check() {
  50. return this.evaluate(function() { //HÄR JUST
  51. return document.querySelectorAll('#my-select').length > 0;
  52. });//
  53. }, function then() {
  54. this.fillSelectors('#my-select', {
  55. 'input[id="id1"]': "dummydata"
  56. }, false);
  57.  
  58. //Here seems the error to be, this.click button:
  59. this.click("button.submit.id_submit");
  60. this.then(nextfunction); //var grabYear
  61. },function timeout() { // step to execute if check has failed
  62. this.echo("TimeOut1").exit();
  63. });
  64. },function timeout() { // step to execute if check has failed
  65. this.echo("TimeOut2").exit();
  66. });
  67. }
  68. });
  69. }
Add Comment
Please, Sign In to add comment