1

I am trying to select multiple elements using xpath in Selenium IDE. The query i am using is

//*[contains(@id, "address_menu_")]

This works for the first element, but there are 8 on the screen that I am trying to target. Any thoughts? Thanks.

*Edit - here is the HTML copied over from Firebug. I extended the product, but the left the other ones minimized for space. The first four products are gift announcements (the functionality I am testing)) and the last 4 are actual products. For the record, what I am trying to target is -

<td class="item-address"> <select id="address_menu_71740515" name="address_71740515">

<script type="text/javascript">
<tr id="item_71740515" class=" odd gift_cont">
<th class="sub">
<td class="product">1 x Gift Announcement (Physical)</td>
<td>
<td class="item-address">
<select id="address_menu_71740515" name="address_71740515">
</td>
<td class="price">$0.00</td>
<td class="price">$0.00</td>
</tr>
<tr class="gift_sep">

<script type="text/javascript">
<tr id="item_71740511" class=" gift_cont">
<tr class="gift_sep">

<script type="text/javascript">
<tr id="item_71740507" class=" odd gift_cont">
<tr class="gift_sep">

<script type="text/javascript">
<tr id="item_71740503" class=" gift_cont">
<tr class="gift_sep">

<tr id="item_71740495" class=" odd">

<tr id="item_71740487" class=" ">

<tr id="item_71740499" class=" odd">

<tr id="item_71740491" class=" ">

2 Answers 2

1

Actually it is not possible to do this way in Selenium. Many of its commands intended to work with exact one element. Although you can do it another way, just clarify your question what do you need exactly?

Now it seems that I understood what you are doing. You have selects inside <td>.
//*[contains(@id, "address_menu_")][1] allows to select only from siblings, but your selects are obviously not those.

If you have all of them in one table then you can slightly change expression, e.g.:

//tr[contains(@id, 'item_')][1]/descendant::select 
//tr[contains(@id, 'item_')][2]/descendant::select
Sign up to request clarification or add additional context in comments.

11 Comments

I am trying to select from 8 different dropdown boxes. The default target for each of the address selection boxes is id=address_menu_71740043 (with a varying number string). I had used the previous xpath target before, so I had assumed there might be a way to select the first, second, third, and so on. Any help would be appreciated!
@kroe761 , first of all check whether this is a typo in question or in you actual code, you have not closing bracket ]
@kroe761, second you can try to select only one element by using sequence number, e.g. //*[contains(@id, "address_menu_")][8]
Yes, there was a typo. Thanks :-) //*[contains(@id, "address_menu_")][1] did target the first element, but //*[contains(@id, "address_menu_")][2] did not target the second element. I think i can make it work by selecting just the last element. Add an element, edit the last, add another element, edit the last, etc. Is there a way to do that? Once again, thanks for your help!
@kroe761 provide more info of what you are trying to do. You want to test <select> html-elements? In turn? Select first and check its value then second?
|
0

You can use:

<tr>
    <td>addSelection</td>
    <td>Locate your select element</td>
    <td>Option you need to select</td>
</tr>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.