2017-07-26 8 views
0

最近、ウェブサイトの更新後までしばらくスクリプトを実行していました。私は何をやっていたウェブサイトの更新後にcasperjs(phantomjs)がフォームを送信できません

https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry

、フォームを記入提出クリックして、結果をこするでした。

私は何をしても、クリックしてEnterキーを送信しても問題はないようです。フォームは送信されません。

私はキャスパーから次のデバッグ行があります。

casperjs casper1.js 
[info] [phantom] Starting... 
[info] [phantom] Running suite: 4 steps 
[debug] [phantom] opening url: https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry, HTTP GET 
[debug] [phantom] Navigation requested: url=https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry" 
[debug] [phantom] Successfully injected Casper client-side utilities 
[info] [phantom] Step anonymous 2/4 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200) 
[info] [phantom] Step anonymous 2/4: done in 1579ms. 
[info] [phantom] Step _step 3/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200) 
[info] [phantom] Step _step 3/5: done in 1599ms. 
[info] [phantom] waitFor() finished in 40ms. 
[info] [phantom] Step anonymous 4/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200) 
[debug] [phantom] Mouse event 'mousedown' on selector: form#form1 
[debug] [phantom] Mouse event 'mouseup' on selector: form#form1 
[debug] [phantom] Mouse event 'click' on selector: form#form1 
[info] [phantom] Step anonymous 4/5: done in 1691ms. 
[info] [phantom] Step anonymous 5/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200) 
[debug] [phantom] Capturing page to /var/www/html/poc/phantom/test.png 
[info] [phantom] Capture saved to /var/www/html/poc/phantom/test.png 
[info] [phantom] Step anonymous 5/5: done in 1964ms. 
[info] [phantom] Done 5 steps in 1967ms 
[debug] [phantom] Capturing page to /var/www/html/poc/phantom/test0.png 
[info] [phantom] Capture saved to /var/www/html/poc/phantom/test0.png 
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "about:blank" 

var casper = require('casper').create({ 
    verbose: true, 
    userAgent: 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36', 
    XSSAuditingEnabled: false, 
    logLevel: 'debug', 
    javascriptEnabled:'false', 
    viewportSize: { 
      width: 1280, 
     height: 720 
    }, 
    pageSettings: { 
     ignoreSslErrors: true, 
     loadImages: false, // do not load images 
     loadPlugins: false, // do not load NPAPI plugins (Flash, Silverlight, ...) 
     webSecurityEnabled: false, 
     localToRemoteUrlAccessEnabled: false 
    } 
}); 

casper.start('https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry', function() { 
    // Wait for the form 
    this.waitForSelector('form#form1'); 
}); 

casper.then(function() { 
    // fill the form 
    this.fill('form#form1', { "ph_pagebody_0$phthreecolumnmaincontent_0$panel$VehicleSearch$RegistrationNumberCar$RegistrationNumber_CtrlHolderDivShown": "ZJD402" }, false); 
    this.click('form#form1'); 
}); 

casper.then(function() { 
     this.capture('test.png'); 
}); 

casper.run(function() { 
    // dump 
    this.capture('test0.png'); 
    //this.debugPage(); 
    this.exit(); 
}); 

を私はまた、結果を含むセレクタを待って試してみましたが、それが到着したことがありません。

phantomjs/casperjs gurusには、自分の袖の上にどんなトリックがありますか?

答えて

1

送信ボタンはクリックせず、フォーム全体をクリックします。

this.click('form#form1'); 

処方箋はボタンではないので、「クリック可能」ではありません。送信ボタンを探してクリックする必要があります。この場合、私はこれを正しく行います:

this.click('"#main input[type='submit']"'); 

それだけです。あなたが実際にsubmitを探していましたが、私は、フォーム上で直接submitを呼び出すと、ボタンに添付されているonClickイベントをトリガすることはないと思うので、あなたは、ユーザーのアクションに100%をシミュレートしたい場合はthinghy 'form#form1'

直接フォームを送信するよりも、ボタンをクリックする方が良いです。

フォームを直接送信するには、fillメソッドの最後にfalseという属性を削除してください。

+0

あなたのお時間をいただき、ありがとうございました。 私の他の考えは、phantomjsのjavascriptを無効にしたバージョンを使用していました。 – vivvvi

+1

@vivvvi Woahは、「あなたの時間に感謝しています」と言っている「低得点」ユーザーです。それは今日ここでは難しいxDです、私はそれを感謝します。 –

+0

waitfor( 'element')が機能していないので、私は待っていることで差が出るとは思っていません。 私の他の考えは、ヘッドレスブラウザでJavaScriptを無効にすることによって拘束される可能性のあるこのようなイベントを排除することでした。 – vivvvi

関連する問題