我遇到Xpath问题。
我有:
<ul unselectable="on" class="k-list k-reset" tabindex="-1" role="listbox" aria-hidden="true" id="1 (fix but random)" aria-live="off" style="overflow: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">standard 2014</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="1 (fix but random)__PackageId_option_selected" aria-selected="true">standard couple 2014</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Gratuit</li>
</ul>
<ul unselectable="on" class="k-list k-reset" tabindex="-1" role="listbox" aria-hidden="true" id="2 (fix but random)" aria-live="off" style="overflow: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">standard 2014</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="1 (fix but random)__PackageId_option_selected" aria-selected="true">standard couple 2014</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Gratuit</li>
</ul>
<ul unselectable="on" class="k-list k-reset" tabindex="-1" role="listbox" aria-hidden="true" id="RANDOM" aria-live="off" style="overflow: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">standard 2014</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="1 RANDOM__PackageId_option_selected" aria-selected="true">standard couple 2014</li><li tabindex="-1" role="option" unselectable="on" class="k-item">Gratuit</li>
</ul>
我的问题很简单:如何在最后一次点击casper&lt; li>标准2014? 我试着这样说:
var x = require('casper').selectXPath;
this.click(x('//*ul[@class="k-list k-reset"]/li[text() = "standard 2014"]'))
但casperjs找不到。 谢谢你的帮助!
答案 0 :(得分:1)
尝试在括号中包围xpath并在末尾添加[last()]
。与(xpath)[last()]
您还应该从//*ul
它应该是这样的:
this.click(x('(//ul[@class="k-list k-reset"]/li[text() = "standard 2014"])[last()]'))
答案 1 :(得分:0)
您应该尝试在浏览器的控制台中检查您的X路径是否有效。像
$x('//a[contains(text(),"Cancel")]')