以下是涉及链接的所有内容:
<a class="" data-images="{"detail_url":"//assets.supremenewyork.com/148393/ma/hBwFmRXhVKI.jpg","zoomed_url":"//assets.supremenewyork.com/148393/zo/hBwFmRXhVKI.jpg"}" data-style-name="Black" data-style-id="19033" data-sold-out="false" data-description="null" href="/shop/bags/lkav6jh17/xfdbgpiea" data-no-tubolink="data-no-tubolink"><img width="32" height="32" src="//d17ol771963kd3.cloudfront.net/148393/sw/hBwFmRXhVKI.jpg" alt="Hbwfmrxhvki"></a>
我使用带有原子编码 Node 的 Nightmare ,并想从以下网址单击黑色书包:http://www.supremenewyork.com/shop/bags/lkav6jh17/p9ylgt8vm
使用元素中找到的“data-style-name=”Black”。
我已经尝试过:
.click("data-style-name ='Black'")
这给了我错误:
Failed to execute 'querySelector' on 'Document': 'data-style-name ='Black'' is not a valid selector.
不确定要点击什么,但任何帮助都会很棒。该链接是图像,是网页上列表元素的一部分。
最佳答案
首先获取 DOM Node 并分配给一个变量,然后单击该 Node 。此外,您还需要在选择器周围添加括号,并且不需要内部单引号,除非值中存在空格或其他无效字符
var myLink = document.querySelector("[data-style-name=black]");
.click(myLink)
关于javascript - 如何使用 Nightmare 点击此链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50595588/