2014-11-09 8 views
0

Я пытаюсь сделать снимок экрана со страницы 1 и страницы 2 с страницы ASP с обратной передачей. Я пытаюсь использовать casperjs для доступа к первой странице и сохранения скриншота, затем нажмите «Далее» и сделайте снимок экрана со второй страницы.Нажмите, чтобы перейти на следующую страницу с обратной передачей

Мой код хорошо работает с некоторыми другими сайтами, но мне это тяжело.

Мой код выглядит следующим образом:

var casper = require('casper').create({logLevel: "debug", verbose: true }); 
casper.start('http://www.slot.pt/JobVacancies', function() { 
    this.capture('Step1.png'); 
    this.wait(5000, function() { 
     this.click('#ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1)'); 
    }); 
}); 

casper.run(function() { 
    this.capture('Step2.png'); 
    this.echo('finished'); 
    this.exit(); 
}); 

отладочная информация:

[info] [phantom] Starting... 
[info] [phantom] Running suite: 2 steps 
[debug] [phantom] opening url: http://www.slot.pt/JobVacancies, HTTP GET 
[debug] [phantom] Navigation requested: url=http://www.slot.pt/JobVacancies, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "http://www.slot.pt/JobVacancies" 
[debug] [phantom] Navigation requested: url=http://platform.twitter.com/widgets/tweet_button.d58098f8a7f0ff5a206e7f15442a6b30.pt.html#_=1415538373180&count=none&id=twitter-widget-0&lang=pt&original_referer=http://www.slot.pt/JobVacancies&size=m&text=S L O T - Ofertas de Emprego&url=http://www.slot.pt/JobVacancies, type=Other, willNavigate=true, isMainFrame=false 
[debug] [phantom] Successfully injected Casper client-side utilities 
[info] [phantom] Step anonymous 2/2 http://www.slot.pt/JobVacancies (HTTP 200) 
[debug] [phantom] Capturing page to /home/netlisbon/test/Step1.png 
[info] [phantom] Capture saved to /home/netlisbon/test/Step1.png 
[info] [phantom] Step anonymous 2/2: done in 1559ms. 
[info] [phantom] Step _step 3/3 http://www.slot.pt/JobVacancies (HTTP 200) 
[info] [phantom] Step _step 3/3: done in 1560ms. 
[info] [phantom] wait() finished waiting for 5000ms. 
[debug] [phantom] Mouse event 'mousedown' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[debug] [phantom] Mouse event 'mouseup' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[debug] [phantom] Mouse event 'click' on selector: #ctl00_ctl00_MainContent_MainContent_dvwListItems_PGB a.dxp-button.dxp-bi:nth-of-type(1) 
[info] [phantom] Done 3 steps in 6571ms 
finished 
[debug] [phantom] Capturing page to /home/netlisbon/test/Step2.png 
[info] [phantom] Capture saved to /home/netlisbon/test/Step2.png 

Однако обе скриншоты показывают ту же страницу ... Я попытался нажать на другую стрелку, чтобы перейти к на последней странице, но я получаю тот же результат.

Может кто-нибудь узнать, что я делаю неправильно здесь?

ответ

0

Функциональность postback - это JavaScript, и это не вызывает шаг навигации. Но поскольку шаги CasperJS ждут только завершения текущего шага навигации, сценарий заканчивается перед загрузкой следующей «страницы».

Вам придется либо ждать статическую количество времени после клика

this.wait(5000, function() { this.click('selector'); }); 
this.wait(5000); 

или даже лучше, вы уследить на какой странице вы находитесь и ждать конкретной страницы появится:

var page = 1; 
this.wait(5000, function() { 
    this.click('selector'); 
    page++; 
}); 
this.waitFor(function check(){ 
    return this.fetchText(".dxp-summary").indexOf("Page " + page + " of ") === 0; 
}, function then() { 
    // screenshot or whatever 
}); 
+0

это решило, спасибо – peixotorms

Смежные вопросы