Casperjs CasperError:无法在不存在的选择器上调度鼠标下移事件
Casperjs CasperError: Cannot dispatch mousedown event on nonexistent selector:
我是使用Casperjs的新手,我试图让这个脚本复制一些文本,但它无法找到搜索按钮,即使我有正确的路径。我已经能够单击脚本中的所有按钮之前,但它给出的错误行:
casper.wait(2000, function () {
casper.click(x('//*[@id="SRCHBTN"]')); <----Error here
casper.capture('CurrentScreen.png');
});
CasperError: Cannot dispatch mousedown event on nonexistent selector:
代码如下:
var casper = require('casper').create();
var x = require('casper').selectXPath;
casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
casper.start('url');
casper.then(function () {
this.sendKeys('user', 'user');
this.sendKeys('pswd', 'pass');
console.log('Entering Data');
});
casper.thenClick(x('//*[@id="login"]/table[1]/tbody/tr[3]/td[2]/input'), function () {
console.log('Logging in..');
});
casper.wait(2000, function () {
casper.click(x('//*[@id="SRCH_LINK"]/a'));
});
casper.wait(2000, function () {
casper.click(x('//*[@id="SRCHBTN"]'));
casper.capture('CurrentScreen.png');
});
casper.wait(4000, function () {
casper.click(x('//*[@id="TITLE_HL$0"]'));
casper.wait(2000, function() {
//this is pop up window section
casper.waitForPopup(/popup'.html$/, function () {
this.test.assertEquals(this.popups.length, 1);
});
// this will set the popup DOM as the main active one only for time the
// step closure being executed
casper.withPopup(/popup'.html$/, function () {
this.test.assertTitle('Job Details - Google Chrome');
var targetText = casper.fetchText('#DESCR');
console.log(targetText);
});
// next step will automatically revert the current page to the initial one
casper.then(function () {
this.test.assertTitle('Main page title');
});
});
});
casper.run();
如果期望元素的存在依赖于异步调用,则等待2秒将不能保证调用完成。你应该使用waitForSelector()
函数来代替wait()
:
casper.waitForSelector(x('//*[@id="SRCHBTN"]'), function () {
casper.click(x('//*[@id="SRCHBTN"]'));
casper.capture('CurrentScreen.png'); });
});
相关文章:
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- 当鼠标悬停在文本中的单词上时显示警报
- JsFiddle上的鼠标事件不起作用
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 将鼠标旋转限制为特定的度数
- 跟踪jqplot垂直折线图的鼠标位置
- node-webkit-从父窗口捕获iframe鼠标事件
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- 调度没有'无法立即更新组件
- 在dhtmlx调度程序中多次触发OnEventSave
- Javascript-在视频中跟踪鼠标位置
- JQuery UI可拖动潜水与滚动棒到鼠标
- 如何在jquery中找到鼠标滚轮/触摸移动事件的走向
- 调度鼠标移动超时
- Casperjs CasperError:无法在不存在的选择器上调度鼠标下移事件
- Casper:无法在不存在的选择器上调度鼠标下移事件
- 如何调度鼠标滚轮事件在旧的IE
- 在另一个DOM元素上调度鼠标滚轮事件