【问题标题】:NightwatchJS can't locate 2nd element out of list of elementsNightwatchJS 无法从元素列表中找到第二个元素
【发布时间】:2019-09-12 22:30:32
【问题描述】:

我正在尝试查找产品图片列表,然后找到第二张产品图片以单击它,但 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


    【解决方案1】:

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

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

    在调用时更改索引。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多