Quality Testing

Quality is delighting customers

Testing dynamic values (values from drop down) in selenium

While performing selenium testing, i came accross a problem with dynamic values.
When i try to test drop down, an error occurs and testing cannot be carried further.Plz guide me to th'h this ...

Views: 406

Reply to This

Replies to This Discussion

Please elaborate kind of error you are getting.

 

 

please specify the error.
You have to use xpath to find the element if the ID is dynamicc
Selenium.Selenium Exception: Error- not found is the error i get when i select the drop down.
May be the element ID is dynamic..so u r getting that error..pls send code of the page and scrrnshot of the page
yes. the ID is dynamic.... that's the reason for d error
please send the code or URL of the site

Let's start with a small table with a Select list inside of it.

 

<table id="testRuns" border="0"  valign="top" align="left" cellpadding=0 cellspacing=0 class="TABLE_section_bar2">
<tr valign="top">
<td valign="top" class="TD_tool_bar1"><b>Show testcases by testrun: </b></td>
<td valign="top" class="TD_tool_bar1">
<select id="some_dynamic_value"  multiple  size=2  class="select_small">
<option value="0" selected>---<br>
<option value="1505_2557">R10.4_Preprod<br>
<option value="1505_2785">R10.5_Preprod<br>
<option value="1505_3272">R10.6_Preprod<br>
<option value="1505_3340">R11.1_PreProd<br>
<option value="1505_3506">R11.2_Preprod
</select>
</td>
</table>

What you want to do to gain access to the select list is move backwards in the DOM until you have a clear and consistent path to the select list. In the case above, as long as my TABLE always has an ID of "testRuns" and my select list is always inside a TD tag, and there is only one TD with a select list in that table, we could do this...

 

String[] options = selenium.getSelectOptions("//table[@id='testRuns']//tr//td[@class='TD_tool_bar1']//select");

 

There is a possibility that your select list has a class or some additional attribute that will help in locating it. In the example above I could add the class to the select to make it more specific...//select[@class='select_small']

 

If you want the ID of the select list, you can ask for it like this...

String selectID = selenium.getAttribute("//table[@id='testRuns']//tr//td[@class='TD_tool_bar1']//select[@class='select_small']@id");

 

Then, getting the values is as easy as ...

String[] options = selenium.getSelectOptions("//select[@id='" + selectID + "']");

 

or

String[] options = selenium.getSelectOptions("//select[@id='" + selenium.getAttribute("//table[@id='testRuns']//tr//td[@class='TD_tool_bar1']//select[]@id") + "']");

thanx a ton Jan!!!

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2022   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service