How to click on Links or Buttons with in WebTable Cell or Table cell
Some time automation engineers may need to click on Button/Links/Images/Radio buttons/select items from List boxes in a given table cell. To achieve that goal uses can use the following
Syntax
Tableobject.ChildItem(row,column,micclass,index)
Note:- micclass field is case sensitive.
Index will start from zero and will vary by no of similar objects in the given cell.
Below is the an example which can give an overview how it works
Note :- If you are looking to reproduce the table above copy the below code and save the code in notepad with file extension as "html"
<html>
<body>
<table border="1">
<TR><TD>Sample Buttons</TD><TD> Demo </TD></TR>
<TR><TD><Center><Input type=Button name="s1" value="Button1"></Input><Input type=Button name="s1" value="Button1"></Input></Center></TD><TD> Demo </TD></TR>
<TR><TD>Two Buttons in the same table cell</TD><TD> Demo </TD></TR>
</table>
</body>
</html>
The above table contains two columns with three rows.
QTP Code to click on WebButtons
' To click on the first button
Set objButton1 = Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",0)
objButton1.highlight
objButton1.click
' To click on the second button
Set objButton2 = Browser("Browser").Page("Page").WebTable("Sample Buttons").ChildItem(2,1,"WebButton",1)
objButton2.highlight
objButton2.click
Alternatively we can use the below code
' To click on the first button
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"WebButton",
0).Click
' To click on the second button
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"WebButton",
1).Click
The same concept will apply for WebLink or Images etc but the Micclass will change in the ChildItem method
If you are looking to handle WebLinks then
' To click on the first link
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"Link",
0).click
' To click on the second link
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"Link",
1).click
If you are looking to handle Images then
' To click on the first image
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"Image",
0).click
' To click on the second image
Browser
("Browser").Page
("Page").WebTable
("Sample Buttons").ChildItem
(2,
1,
"Image",
1).click
Also Note that Index value in the childItem method will vary depending on the number of similar objects present in the cell.