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



我正在尝试查找产品图片列表,然后找到第二个产品图片以单击它,但夜巡找不到它。该页面 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 文档的元素属性部分,您可以在页面对象上定义索引以获取与您的选择器匹配的元素的第二个实例,或者执行类似操作

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

以在调用时更改索引。

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

相关内容

最新更新