Showing posts with label XPath. Show all posts
Showing posts with label XPath. Show all posts

Friday, 14 October 2011

Replace value in XPath with Variable

Below is the sample piece of code for submitting the variable into XPath.
Selenium IDE
<tr>
    <td>store</td>
    <td>2</td>
    <td>a</td>
</tr>

Verify the A value
<tr>
    <td>echo</td>
    <td>${a}</td>
    <td></td>
</tr>

//Replace the hardcoded value with a
<tr>
    <td>click</td>
    <td>//*[@id='ctl00_Main_DropDown']/div/ul/li[${a}]</td>
    <td></td>
</tr>

In Selenium RC
String a = "2";
System.out.println(a);
selenium.click("//*[@id='ctl00_Main_DropDown']/div/ul/li[" + a + "]");