node.js - 有没有办法通过 Puppeteer 中的两个属性找到按钮?

标签 node.js puppeteer

我正在尝试使用 puppeteer 单击按钮,并且我正在尝试通过其两个属性 aria-scribedbytitle 找到它,因为它不没有身份证。 aria-describeby 属性的值是我设置的名称,但是最后两个字符是数字,会自动更改为随机数。

我搜索了正则表达式问题、JS 问题、puppeteer 的代码,但没有任何实际效果。

我得到的最接近的是:

//v1
const arr = await page.$x('//button[starts-with("aria-describedby", "someName")]');
await arr[1].click();

//v2
page.click('button[aria-describedby="someName20"][title="Click button"]');

我尝试了不同的代码,但几乎总是得到未定义找不到选择器的 Node

最佳答案

您可以尝试使用 css 开头选择器 (^=):

button[aria-describedby^="someName"][aria-label="Click button"]

关于node.js - 有没有办法通过 Puppeteer 中的两个属性找到按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55975643/

相关文章:

javascript - 在带有 jade 模板的 Express.js 中使用公开的对象作为值或助手?

node.js - OpenAI GPT-3 API 错误 : "TypeError: Converting circular structure to JSON" using ExpressJS

javascript - NodeJS : invalid array length Allocation failed - JavaScript heap out of memory

python - 无法强制 puppeteer 点击 iframe 中的验证码

javascript - Puppeteer 不关闭浏览器

node.js - Azure Linux Web App 上 Node 中的 wkhtmltopdf 或 puppeteer

node.js - 如何使用 express 在 Chrome 中获取 net::ERR CONTENT LENGTH MISMATCH

javascript - 错误 : Can't set headers after they are sent. RabbitMQ 干扰 NodeJS 响应

node.js - 使用 azure 管道部署 create-react-app

javascript - 等待使用 puppeteer 显示 Google Captcha