google-chrome-devtools - 为什么 Puppeteer elementHandler 没有选择器参数?
问题描述
这是我的代码:
const $container = $('.container');
$container.on('click', '#btn', function(){});
如何触发按钮的事件?
解决方案
对不起,我忘记了这个问题。
await page.waitForSelector(INPUT_SELECTOR, {timeout: 15000});
const pointer = await page.evaluate((sel) => {
const rect = document.querySelector(sel).getBoundingClientRect();
return [(rect.top + rect.height) / 2, (rect.left + rect.width) / 2];
}, INPUT_SELECTOR);
await page.mouse.click(...pointer);
只需使用本机鼠标事件。
推荐阅读
- python - 如何在pylatex的乳胶表的单元格中添加对图形的引用
- .net-core - CS0266 无法隐式转换类型
- javascript - 循环中的 JSON 解析排序
- wordpress - WordPress 是否具有允许重复发布的内置功能?
- haskell - Haskell:关于部分应用的问题
- ruby-on-rails - Ruby gem 方法仅在控制器中可用?如果是这样,如何使其在其他文件中可用?
- apache-spark-mllib - TransmogrifAI 通过 MLeap 与 MLFlow 兼容吗
- c# - 带有访问修饰符的显式接口实现
- java - 声纳扫描仪扫描的问题远少于soanr扫描的问题:soanr
- linux - 当我学习 pwn 时,使用 gdb 调试,但程序集返回失败