これは、Web ページの UL を含む Div です。
<div id='sites'>
<ul style="display: block;">
<li data-product-id="55">
<a href="#">Test1<br><em class="environment">Production</em></a>
</li>
<li data-product-id="99">
<a href="#">Test2<br><em class="environment">Production</em></a>
</li>
<li data-product-id="98">
<a href="#">Test3<br><em class="environment">Production</em></a>
</li>
<li data-product-id="61">
<a href="#">Test4<br><em class="environment">Production</em></a>
</li>
<li data-product-id="97">
<a href="#">Test5<br><em class="environment">Production</em></a>
</li>
<li class="active">
Test6<br><em class="environment">Production</em> <a class="flat button" href="/product_center">Settings</a>
</li>
</ul>
</div>
ページはデフォルトでTest6 ulをロードし、 Test5をクリックしたいと思います。
Firepath が提供する CSS ロケーターは"#sites>ul>li>a"
. だから私はcasperjsでこれを試しました:
var casper = require('casper').create({
verbose: true,
logLevel: "debug",
});
casper.start('http://localhost:8080', function() {
this.echo(this.getTitle());
});
casper.then(function(){
casper.page.injectJs('jquery.js');
this.evaluate(function (){
$("#sites>ul>li")[4].click();
});
this.capture('screenshot.png');
});
casper.then(function() {
this.echo(this.getTitle());
});
出てくるタイトルは常に現在のページのものです。Test5 をクリックして、Test5 ページのタイトルを取得する必要があります。
私が間違っていることは何ですか?