简体   繁体   English

单击带有 javascript 的网页中的按钮 - 错误?

[英]Clicking a button in a webpage with javascript - error?

Noob Question;菜鸟问题; HTML is HTML是

    <button aria-label="Navigate to page 40" data-page- 
     number="40" type="button" data-ember-action="" data- 
      ember- 
      action-582="582" data-is-animating-click="true">
       40
     </button>

I thought the code would be我以为代码是

       document.querySelector('button.Navigate.to.page.40').click()

But apparently this isn't a valid selector... what am I doing wrong?但显然这不是一个有效的选择器......我做错了什么?

You need to use the selector button[aria-label="Navigate to page 40"] :您需要使用选择器button[aria-label="Navigate to page 40"]

 const button = document.querySelector('button[aria-label="Navigate to page 40"]'); console.log(button);
 <button aria-label="Navigate to page 40" data-page- number="40" type="button" data-ember-action="" data- ember- action-582="582" data-is-animating-click="true"> 40 </button>

Your selector button.Navigate.to.page.40 is valid, but it means: select a <button> which has classes of Navigate , to , page , and 40 (which of course isn't the case for this HTML).您的选择器button.Navigate.to.page.40是有效的,但这意味着:选择一个<button> ,它具有Navigatetopage40 (当然这个 HTML 不是这种情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM