JavaScript 等待点击
我有 x 页,每页包含 15 个对象的列表。我想浏览所有页面,下载列表中 15 项中每一项的文本。下载有效,但相同的元素被写入变量“a”(可能是因为代码执行速度比在代码内单击更快)。是否可以使其休眠/等待执行,然后转到下一页?
var a = '';
for (let i = 0; i < 999; i++) {
const paragraphs = document.querySelectorAll(".my-object-on-list");
paragraphs.forEach(p => a = a + p.outerText);
angular.element(document.getElementsByClassName('btn-forward')).click();
setTimeout(1);//sleep for 1s?
}
I have x - pages of lists of 15 objects each. I would like to go through all the pages downloading the text of each of the 15 items in the list. The download works, but the same elements are written to the variable "a" (probably because the code executes faster than clicking from within the code). Is it possible to put it to sleep / wait for execution and then go to the next page?
var a = '';
for (let i = 0; i < 999; i++) {
const paragraphs = document.querySelectorAll(".my-object-on-list");
paragraphs.forEach(p => a = a + p.outerText);
angular.element(document.getElementsByClassName('btn-forward')).click();
setTimeout(1);//sleep for 1s?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的脚本有很多问题
试试这个
There are many problems in your script
Try this