gpt4 book ai didi

javascript - Casperjs Casper错误: Cannot dispatch mousedown event on nonexistent selector:

转载 作者:行者123 更新时间:2023-11-28 15:40:19 28 4
gpt4 key购买 nike

我是 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'); });
});

关于javascript - Casperjs Casper错误: Cannot dispatch mousedown event on nonexistent selector:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24001453/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com