nightwatch.js - NightwatchJS 无法从元素列表中找到第二个元素
问题描述
我正在尝试查找产品图片列表,然后找到第二张产品图片以单击它,但 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 文档的元素属性部分,您可以在页面对象上定义索引以获取与选择器匹配的元素的第二个实例,或者执行类似的操作
.waitForElementVisible({ selector: '@xpathproduct', index: 1 }, 1000)
在调用时更改索引。
注意:我认为文档中关于传递获取第二个元素的索引是不正确的;以我的经验,index: 0
获得第一个元素,index: 1
您想要获得第二个元素也是如此。
推荐阅读
- python - 得到错误 IndentationError: 期望 python 代码中的缩进块
- kubernetes - 了解 GCP 监控中的 Kubernetes pod 资源利用率
- amazon-web-services - 使用无服务器框架如何使用 Cloud Watch 事件记录 Amazon S3 对象级操作
- r - r 中的正则表达式在句点后添加空格(如果不存在)
- php - 为什么这在 PHP 7.2 上给我一个语法错误,但在 PHP 7.4.5 上却没有?
- laravel - Laravel 从 Livewire 到 Fotify
- r - 复制data.frame的最快方法
- java - Springboot 手动 JAR 无法正常运行
- spring-batch - Spring批量访问内部表中的数据
- python - 如何在pygame中移动一个矩形