1

I have quite specific problem regarding both selenium and xpath.

I have to make an automated tests based on scenarios using selenium. All pages are automatically generated and using Ids is impossible.

All form elements though are designed in same way.

 <table>
 <tr><td> Title </td></tr>
 <tr><td> input/dropdown/etc </td></tr>
 </table>

He is the specifics

<tr>
<td width="34%" valign="top" bgcolor="#ffffc7">
<span class="bold">Status wniosku</span>
<span>Test</span>
</td>
<td width="66%" bgcolor="#ffffc7">
<select id="ctl00_ContentPlaceHolder_2041" class="baseCtrl" name="ctl00$ContentPlaceHolder$2041">
<option value="" selected="selected">- wybierz -</option>
<option value="save">tylko zapisz</option>
<option value="pj">zapisz i wyślij do PJ</option>
</select>
<span>
</span>
<span id="ctl00_ContentPlaceHolder_ctl19" class="validation" style="display:none;">Określ status wniosku</span>
<span id="ctl00_ContentPlaceHolder_ctl20" class="validation" style="display:none;"></span>
<span></span>
</td>
</tr>

Using http://www.xmlme.com/XpathTool.aspx I have designed xpath for dropdown elements.

//span[text()='LABELNAME']/ancestor::*[1]/following-sibling::*/select/option[text()='TEXTVALUE']

I would like to use Selenium to click on the element i found. I've tried Selenium.Click() and variations of Selenium.Select() but with no results.

My question is, is the xpath designed correctly? If so how should i execute it using Selenium? Thx for the help.

2
  • In your example HTML above, what exact element are you trying to click? It's hard to tell. Also what browser are you using for this? Commented Feb 19, 2013 at 15:17
  • I'm using internet explorer. I'm trying to click one of the dropdown options. I'm not sure if i should be clicking it or selecting it. In my expath im trying to click 'tylko zapisz'. Selenium.Click("//span[text()='Status wniosku']/ancestor::*[1]/following-sibling::*/select/option[text()='tylko zapisz'"); Commented Feb 19, 2013 at 15:28

1 Answer 1

1

Try below xpath for selecting second option

"//span[text()='Test']/ancestor::*[1]/following-sibling::*/selec‌​t"

Ex:

Selenium.Select("//span[text()='Test']/ancestor::*[1]/following-sibling::*/selec‌​t","label=Save");
Sign up to request clarification or add additional context in comments.

2 Comments

It's not working but it gave me the idea of how it should work :) Selenium.Select("//span[text()='Test']/ancestor::*[1]/following-sibling::*/select","label=Save"); Please edit your post with update so i can thumb up! :)
It is my pleasure to help you.. :) I've edited my answer bcz, It may useful to some other.

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.