Thursday, August 16, 2012

Clicking an item inside Table


Here is the post that discusses how to click an item inside table.
It may be possible that when you are automating page containing web table it will contain objects such as links, images etc.We may require to click such objects and write code for it.
For such condition we can use below code:
Set otable=browser(“browser”).Page(“page”).WebTable(“table”)
table.ChildItemCount(1,1,”Link”)
If icount=1 Then
Set olink=otable.ChildItem(1,1,”link”,0)
olink.click
End If

Explanation of above code
‘setting object to table that contains links/images
Set otable=browser(“browser”).Page(“page”).WebTable(“table”)
‘using child item count inbuilt function
‘this function will count the number of objects in a cell
‘here (1,1) tells about 1st row and 1st column and value in double codes tells about type of “object” that we are looking for.
icount=otable.ChildItemCount(1,1,”Link”)
‘here we used child item inbuilt function.(1,1) signifies 1st row and column or any other cell that contains object that we want to click.”0″ specifies first link in cell to be clicked.
Set olink=otable.ChildItem(1,1,”link”,0)
if cell contains 2 links then we can use code line as below  to click on second link.
Set olink=otable.ChildItem(1,1,”link”,1)
‘it will click on the link
olink.click
We can use “image instead of “link” to click on an image in cell( 1, 1) as shown below:
Set oImage=otable.ChildItem(1,1,”image”,0)
‘it will click on the image
oImage.click
Please feel free to ask any questions.I will resolve all queries within 24 hrs.