Reputation: 209
I'm trying to find a list of product images then locate the 2nd product image to click on it, but nightwatch can't find it. The page is https://www.artsyjewels.com/collections/earrings
Can someone advise me how to click on this? Thanks.
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)
Alternatively I can use CSS selector :nth-of-type(2) and it works, but wondering how to get it to work with above 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
Upvotes: 0
Views: 477
Reputation: 104
Per the Element Properties section of the Nightwatch.js documentation, you can either define an index on your page object to get the second instance of an element matching your selector, or do something like
.waitForElementVisible({ selector: '@xpathproduct', index: 1 }, 1000)
to change the index at call time.
Note: I think the documentation is incorrect about the index to pass to get the second element; in my experience, index: 0
gets the first element, so index: 1
is what you want to get the second one.
Upvotes: 2