use*_*249 7 jquery webpage-screenshot casperjs
我的页面上有html元素,这是在表单登录后的安全页面上
<h4 class="something" id="somethingelse1" style="display: none;">Some Name</h4>
<h4 class="something" id="somethingelse2" style="display: none;">Some other name</h4>
Run Code Online (Sandbox Code Playgroud)
我希望能够模拟此元素的单击,然后将加载新页面.一旦加载了新页面,我想在其中拍摄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');
//});
});
Run Code Online (Sandbox Code Playgroud)
在页面标题之后,控制台只输出"Null".我不确定这是否也是正确的方法.目标是基于我将以编程方式发送的选定文本来模拟H4元素的单击,然后在该单击操作加载名为someelement的div的第2页之后在第2页上创建快照.
UPDATE
页面加载后,h4元素通过jquery动态添加到页面中.
谢谢
尝试等待您的h4内容实际添加到 DOM 中,然后单击它:
casper.waitForSelector("#somethingelse1").thenClick("#somethingelse1");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7329 次 |
| 最近记录: |