Sunday 1 June 2014

QTP-UFT - How to Click on Links or Buttons in the Table Cell


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.





 

23 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Please clarify how to make the Index value a dynamic variable. If it is possible to assign a variable instead of a hard coded value as a number as there might be a large number of objects of the same Micclass on the webpage.

    ReplyDelete
  3. Hi Shilpa,

    please refer to the following link

    http://uftquestions.blogspot.in/2015/01/uft-qtp-how-to-click-on-link-on-web-page.html

    this code contains index value as a dynamic variable.

    Regards,
    Sreenu Babu

    ReplyDelete
  4. Hello I want to click link in webpages could you please tell me how to do

    ReplyDelete