簡體   English   中英

如何使用CasperJS成功提交.Net表單

[英]How to successfully submit .Net form using CasperJS

我正在嘗試提交.Net表單,然后從響應頁面捕獲元素。 .Net表單似乎未正確提交,因為CasperJS只是重新加載了表單頁面。 對於我來說,存儲Google搜索結果的CasperJS示例很好用,但是此表單根本不會加載響應頁面。

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

casper.start("https://jobs.ca.gov/Public/JobVacancySearch.aspx", function(){
    this.fill('#form1', {'ctl00$cphMainContent$txtJobTitle': 'Programmer'}, true);

    this.waitForSelector("#cphMainContent_gvSearchResults");
});

casper.run(function(){
    console.log("success");
});

這是輸出:

casperjs so-test.js --config=<(echo '{"sslProtocol": "any"}') --ignore-ssl-errors=true
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://jobs.ca.gov/Public/JobVacancySearch.aspx, HTTP GET
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/Public/JobVacancySearch.aspx, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://jobs.ca.gov/Public/JobVacancySearch.aspx"
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/MasterContent/headerSiteSearch.html, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/MasterContent/headerSiteSearch.html, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 https://jobs.ca.gov/Public/JobVacancySearch.aspx (HTTP 200)
[info] [remote] attempting to fetch form element from selector: '#form1'
[debug] [remote] Set "ctl00$cphMainContent$txtJobTitle" field value to Programmer
[info] [remote] submitting form to ./JobVacancySearch.aspx, HTTP POST
[info] [phantom] Step 2/2: done in 2070ms.
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/Public/JobVacancySearch.aspx, type=FormSubmitted, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://jobs.ca.gov/Public/JobVacancySearch.aspx"
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/MasterContent/headerSiteSearch.html, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=https://jobs.ca.gov/MasterContent/headerSiteSearch.html, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 3/3 https://jobs.ca.gov/Public/JobVacancySearch.aspx (HTTP 200)
[info] [phantom] Step 3/3: done in 2355ms.
[warning] [phantom] Casper.waitFor() timeout
[error] [phantom] Wait timeout of 5000ms expired, exiting.
Wait timeout of 5000ms expired, exiting.

填寫表單后,單擊“提交”按鈕似乎已解決了此問題。

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

casper.start("https://jobs.ca.gov/Public/JobVacancySearch.aspx");

casper.then(function(){
    this.fill('#form1', {'ctl00$cphMainContent$txtJobTitle': 'Programmer'}, false);
});

casper.then(function(){
    this.click("#cphMainContent_btnFindJobs"); 
});

casper.waitForSelector("#cphMainContent_gvSearchResults", function(){
    console.log("Found search results");
});

casper.run(function(){
    console.log("success");
    this.exit();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM