我的页面上有这样的html元素,在表单登录后的安全页面上
<h4 class="something" id="somethingelse1" style="display: none;">Some Name</h4>
<h4 class="something" id="somethingelse2" style="display: none;">Some other name</h4>
我希望能够模拟这个元素的点击,然后加载一个新页面。加载新页面后,我想对其中的 div 元素进行快照。我已经完成了拍摄快照的一部分,但我无法找到一种基于其文本单击元素的方法。例如模拟上面的 H4 元素的点击,其中文本是“其他名称”
这是我目前所拥有的......
var casper = require('casper').create({
pageSettings: {
loadImages: true,
loadPlugins: true
}
});
casper.start('http://localhost/', function() {
console.log("page loaded");
this.fill('form#login-form', {
username: 'lbguy',
password: 'lbguypass'
}, true);
});
casper.thenOpen('http://localhost/MysecureSite/page1', function() {
this.echo(this.getTitle());
var query_xpath = '//*[@innerHtml="Some other name"]';
require('utils').dump(this.getElementAttribute(query_xpath , 'id'));
//casper.start('http://localhost/MysecureSite/page2', function() {
// this.captureSelector('pic.png', '#someelement');
//});
});
在页面标题之后,控制台只输出“Null”。我不确定这是否也是正确的方法。目标是根据我将以编程方式发送的选定文本模拟 H4 元素的单击,然后在单击操作加载名为 someelement 的 div 的第 2 页后在 page2 上拍摄快照。
更新
h4 元素在页面加载后由 jquery 动态添加到页面中。
谢谢