2015-06-02 38 views
-2

下面是HTML:如何從CasperJS中的多個節點中選擇一個?

<div class="graph_tit" id="graph_tit"> 
<a href="/jsp/home/contents/climateData/smart/smartStatisticsSearch.do" class="on" onclick="return false;">관측자료</a> 
<a href="/jsp/home/contents/climateData/smart/smartStatisticsSearch.do" onclick="return false;" class="">통계자료</a> 
</div> 

我想選擇在CasperJS第二a元素。

但是,<a>節點是相似的。

以下是CasperJS中的代碼嘗試。

$('div[id="graph_tit"] a[class=""]').click(); 

$('div[id="graph_tit"] a[text()="통계자료"]').click(); 
+1

這是一個和你想怎麼選擇? – Satpal

+0
+1

如果alexce的回答沒有幫助你(它應該),那麼其他地方就有問題了。請註冊到'resource.error','page.error','remote.message'和'casper.page.onResourceTimeout'事件([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)) 。也許有錯誤。 –

回答

0

您可以檢查class attribute is empty

this.click('div.graph_tit a[class=""]'); 

您可能還需要等待選擇

this.waitForSelector('div.graph_tit a[class=""]').thenClick('div.graph_tit a[class=""]'); 
+0

仍然無法... –

+0

另外,我用waitForSelector。 –

+0

@龍公what有什麼症狀?任何錯誤? – alecxe

相關問題