![](/img/trans.png)
[英]How can I populate a html select element with the contents of an array using vanilla javascript?
[英]How to select this element in vanilla javascript?
我正在尝试一些网络自动化。 我想选择按钮元素。 我试图解决这个问题,但无法解决
这是按钮--------
<button class="dCJp8 afkep _0mzm-">
<span class="glyphsSpriteHeart__outline__24__grey_9 u-__7" aria-label="Like">
</span>
</button>
来源-Instagram
我尝试了这些方法:
试试document.querySelector('button.dCJp8')
它对我document.querySelector('button.dCJp8')
。
您应该使用 querySelectorAll() 和 getAttribute() 方法返回具有指定名称的元素的属性值。
下面的例子。
var hearts = document.querySelectorAll(".glyphsSpriteHeart__outline__24__grey_9.u-__7")[0].getAttribute("aria-label");
用于在类 glyphsSpriteHeart__outline__24__grey_9.u-__7 中获取属性“aria-label”的velue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.