<button class="button width-full button--primary" data-automation-id="signin-submit-btn" data-tl-id="signin-submit-btn" type="submit"><span class="button-wrapper">Sign in</span></button>我需要用 puppeteer 刮取“data-automation-id”的值,即“signin-submit-btn”。我知道我可以通过这样做来获取文本document.querySelector('button[class="button width-full button--primary"]').innerText;但我需要知道如何获取“data-automation-id”的值
1 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
看起来您正在尝试捕获Data Attribute的值。您可以通过引用按钮元素来完成此操作,dataset如下所示:
let mybutton = document.querySelector('button[class="button width-full button--primary"]');
let autoId = mybutton.dataset.automationId;
console.log(autoId);
<button class="button width-full button--primary" data-automation-id="signin-submit-btn" data-tl-id="signin-submit-btn" type="submit"><span class="button-wrapper">Sign in</span></button>
添加回答
举报
0/150
提交
取消