Wednesday 19 February 2014

how to select a checkbox using webdriver


1.If all checkbox's having Inside one <td> like As
<td>
<input type="checkbox" name="module" value="xxx">
xxx
<br>
<input type="checkbox" name="module" value="yyy">
yyy
<br>
<input type="checkbox" name="module" value="zzz">
zzz
<br>

</td>


 webdriver selecting checkbox script is:

driver.findElement(By.xpath("//input[@name='module' and @value='zzz']")).click(); 
driver.findElement(By.xpath("//input[@name='module' and @value='yyy']")).click();
driver.findElement(By.xpath("//input[@name='module' and @value='xxx']")).click();



2.if all checkbox having one <td> with <table> structure like as

<td width="50%" align="left">
<table border="0" align="left">
<tbody>
<tr>
<td align="left">
<input type="checkbox" name="modules" value="3" style="width:10px">
</td>
<td align="left">zzz</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="modules" value="2" style="width:10px">
</td>
<td align="left">yyy</td>
</tr>
<tr>
<td align="left">
<input type="checkbox" name="modules" value="1" style="width:10px">
</td>
<td align="left">xxx</td>
</tr>

</tbody>
</table>
</td>


webdriver selecting checkbox script is:

driver.findElement(By.xpath("//input[@name='modules' and @value='3']")).click(); 
driver.findElement(By.xpath("//input[@name='modules' and @value='2']")).click();    
driver.findElement(By.xpath("//input[@name='modules' and @value='1']")).click();
 

No comments:

Post a Comment

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...