Abdulla
Abdulla

Reputation: 129

2 same elements on page, how to click second one using watir?

There are 2 images on a page that have the same image src link. If i use the following code it will click the first image, so how do I click on the second image?

browser.image(:src, "https://itc.mzstatic.com/itc/images/btn-grey-small-edit.png").click

Upvotes: 1

Views: 2761

Answers (1)

Alister Scott
Alister Scott

Reputation: 3685

You need to either capture all images, and click the second one

browser.images(:src, "https://itc.mzstatic.com/itc/images/btn-grey-small-edit.png")[1].click

or specify the index of the image (index starts at 0 for watir-webdriver, or 1 for watir):

browser.image(:src => "https://itc.mzstatic.com/itc/images/btn-grey-small-edit.png", :index => 1).click

Upvotes: 9

Related Questions