Pyramid Power
Pyramid Power

Reputation: 35

Selenium click CSS elmenents that have same class name

I'm trying to click the second element where "class=uiComposerAttachment photoAttachment"

Selnium IDE for Firefox

Upvotes: 0

Views: 3274

Answers (5)

Rohit Ware
Rohit Ware

Reputation: 2002

As class is same, you need to identify element as per position. This is second element that you mentioned, so you can use

xpath=(//*[@class="uiComposerAttachment photoAttachment"])[2]

Upvotes: 0

Arran
Arran

Reputation: 25056

Something different from XPath, is using the nth-child locator in CSS. Note this isn't supported in IE8 and below, but other modern browsers will be fine. Example to get the 2nd element:

css=*.uiComposerAttachment:nth-child(2)

Upvotes: 2

HemChe
HemChe

Reputation: 2337

If there are multiple elements with same xpath you can try below format of xpath to click the desired element.

As per your application, you have 2 elements with same xpath. So you can use the below xpath to click on the second element.

xpath=(//select[@name='listPartition'])[position()=2]

Upvotes: 0

Ankit jain
Ankit jain

Reputation: 4318

You have to find the Xpath of the class and use the Xpath then try.

   click | //*[@class='uiComposerAttachment photoAttachment']

Use this in the selenium IDE

Can you provide snapshot, how you find the Xpath of the class

Upvotes: 1

Santoshsarma
Santoshsarma

Reputation: 5667

try this

//*[@class='uiComposerAttachment photoAttachment'][2]

Upvotes: 0

Related Questions