NightwatchJS 无法从元素列表中找到第二个元素

NightwatchJS can't locate 2nd element out of list of elements

我正在尝试查找产品图片列表,然后找到第二张产品图片并单击它,但 nightwatch 找不到它。页面是https://www.artsyjewels.com/collections/earrings
有人可以告诉我如何点击这个吗?谢谢

xpathproduct: (.//div[@class="yit-wcan-container"]//following-sibling::div[@class="jas-product-image pr oh jas-product-image-equal"])[2]

NightwatchJS can't find the element
.waitForElementVisible('xpath', '@xpathproduct', 1000)

或者我可以使用 CSS 选择器 :nth-of-type(2) 并且它有效,但想知道如何让它与上面的 xpath

一起工作
div.jas-grid-item.jas-col-md-3.jas-col-sm-4.jas-col-xs-6.mt__30.product.has-post-thumbnail.user_custom:nth-of-type(2)>div>div.jas-product-image.pr.oh.jas-product-image-equal>a

根据 Nightwatch.js 文档的 Element Properties 部分,您可以在页面对象上定义索引以获取与选择器匹配的元素的第二个实例,或者执行类似

.waitForElementVisible({ selector: '@xpathproduct', index: 1 }, 1000)

在调用时更改索引。

注意:我认为文档中关于传递索引以获取第二个元素的内容不正确;根据我的经验,index: 0 得到第一个元素,所以 index: 1 就是你想要得到的第二个元素。