2013-11-23 56 views
0

我有我的網站的網址,我正在做它與casperjs.I我想要獲得標題和測試類或id在這個頁面中有問題,並將值設置爲通過使用casperjs在本網站的文本框。在Casperjs使用URL Proplem

//var url = 'https://www.google.com.kh/'; 
//this url below it is not work with my code if the url above it work normal 
var url = 'https://teleservices.paris.fr/etatcivil/jsp/site/RunStandaloneApp.jsp?page=formengine&form=naissance'; 

var casper = require('casper').create(); 
    casper.start(url, function() { 
      this.echo(url); 

      this.echo("start page..."); 

    }); 
    casper.then(function(){ 
     this.wait(1000,function(){ 
      this.echo('Page: ' + this.getTitle()); 
      }); 

    }), 
    casper.then(function() { 
      if(this.exists("div.job-search-box-text")){ 
        this.echo("this is id found"); 
       } 
       else{ 
        this.echo("no ID found"); 
       } 

    }), 
    casper.then(function(){ 
     this.wait(1000,function(){ 
      this.fillSelectors('form', { 

        'input[name="title"]' : "12" 
      }); 
      this.capture('result.png'); 
      }); 

}); 


casper.run(); 

我有這個網址的問題,當我設置var url = 'https://teleservices.paris.fr/etatcivil/jsp/site/RunStandaloneApp.jsp?page=formengine&form=naissance'; my result code can not display the title of the web page,can not get the each id or class in this webpage,can not capture....I'm stuck with this anyone have solution , I have tried it for long time,please help me, thanks.

回答

0

我使用OSX小牛casperjs 1.0.2和我沒有問題,顯示標題。 您檢查是否存在div.job-search-box-text,但在兩種情況下它不存在。 輸出錯誤的fillSelectors代碼:沒有名稱標題的輸入字段。

這裏是鏈接https://www.google.com.kh/

https://www.google.com.kh/ 
start page... 
Page: Google 
no ID found 
TypeError: 'undefined' is not a function (evaluating 'this.fillSelectors('form',  {'input[name="title"]' : "12"})') 
/Users/jeff/Downloads/code/automation/casperjs-1.0.3/scripts/test.js:24 
/Users/jeff/Downloads/code/automation/casperjs-1.0.3:1677 in _check 

輸出這裏是鏈接https://www.google.com.kh/

https://teleservices.paris.fr/etatcivil/jsp/site/RunStandaloneApp.jsp?page=formengine&form=naissance 
start page... 
Page: Acte de naissance 
no ID found 
TypeError: 'undefined' is not a function (evaluating 'this.fillSelectors('form', {'input[name="title"]' : "12"})') 
/Users/jeff/Downloads/code/automation/casperjs-1.0.3/scripts/test.js:24 
/Users/jeff/Downloads/code/automation/casperjs-1.0.3:1677 in _check 
+1

TypeError是因爲fillSelectors是在Casper 1.1中引入的http://docs.casperjs.org/en/latest/modules/casper.html#fillselectors – emgee

1

哇輸出 - 我無法弄清楚這是怎麼回事。我得到的代碼工作,但我無法弄清楚究竟是什麼修復它。

這個網站有一些奇怪的地方,有時候我的圖片會404,我注意到一個奇怪的網址結構。注意// CSS/

https://teleservices.paris.fr/etatcivil//css/plugins/images/local/skin/plugins/etatcivil/left-first-srub.gif

我希望有一些關鍵的一課,讓您在這裏 - 我肯定是有的,但我不知道它:)

var url = "https://teleservices.paris.fr/etatcivil/jsp/site/RunStandaloneApp.jsp?page=formengine&form=naissance"; 

var casper = require('casper').create({ 
    logLevel:"debug", 
    verbose: true, 
    waitTimeout: 6000 
}); 



casper.userAgent('Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.1)'); 

casper.start(url, function() { 
    this.echo(url); 
    this.echo("start page..."); 
}); 

casper.waitForSelector('#formengine-menu', function() { 
    this.echo('Page: ' + this.getTitle()); 

}); 

casper.then(function() { 
    if(this.exists("#naissancelieuEtDate")){ this.echo("Form naissancelieuEtDate exists"); } 
    else{ this.echo("no ID found"); } 
}); 

casper.then(function(){ 

    this.fill('#naissancelieuEtDate', { 
      'dateActeJour' : "12" 
    }); 
    this.capture('result.png'); 

}); 

卡斯帕。跑();