casper.waitForSelector不使用动态DOM操作

时间:2015-03-25 12:01:47

标签: javascript phantomjs casperjs

这是我的代码,   具有相同选择器的waitForSelector在动态dom操作之前工作正常。不确定这是不是一个错误。

casper.start("http://www.collierscanada.com/en/Properties?t=2")
# works here
casper.waitForSelector('#propertiesListView')
# changing the number of results displayed per page
casper.click('#dk_container_main_0_results_propResultsPerPage > a > span.dk_arrow > span')   casper.waitForSelector('#dk_container_main_0_results_propResultsPerPage.dk_open')  
casper.click('#dk_container_main_0_results_propResultsPerPage > div > ul > li:nth-child(6) > a')
# same selector does not work here
# some dynamic dom manipulation is happening in between
casper.waitForSelector('#propertiesListView')

错误

[warning] [phantom] Casper.waitFor() timeout
[error] [phantom] Wait timeout of 15000ms expired, exiting

1 个答案:

答案 0 :(得分:0)

casper.start("http://www.collierscanada.com/en/Properties?t=2")
casper.waitForSelector('#propertiesListView', function() {
    casper.click('#dk_container_main_0_results_propResultsPerPage > a > span.dk_arrow > span')
});
casper.waitForSelector('#dk_container_main_0_results_propResultsPerPage.dk_open').thenClick('#dk_container_main_0_results_propResultsPerPage > div > ul > li:nth-child(6) > a')
casper.waitForSelector('#propertiesListView')