【问题标题】:How to select one from a number of nodes in CasperJS?如何从 CasperJS 的多个节点中选择一个?
【发布时间】:2015-06-02 16:10:31
【问题描述】:

以下是HTML:

<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 元素。

但是,&lt;a&gt; 节点是相似的。

以下是CasperJS中的试用代码。

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

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

【问题讨论】:

  • 哪个是你想如何选择?
  • 如果 alexce 的回答对您没有帮助(而且应该),那么其他地方就有问题。请注册resource.errorpage.errorremote.messagecasper.page.onResourceTimeout 活动 (Example)。可能有错误。

标签: javascript css-selectors casperjs


【解决方案1】:

您可以检查class attribute is empty:

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

您可能还需要等待选择器

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

【讨论】:

  • 另外,我习惯waitForSelector。
  • 错误消息:“等待超时 5000 毫秒已过期,正在退出。”
  • @ARongKwon 页面上有 iframe 元素吗?
  • 我尝试了 Chrome 开发。 Chrome 开发运行良好。但是,CasperJS 不是。
  • 此页面上存在 iframe。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-24
  • 2020-05-02
相关资源
最近更新 更多