Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Running JavaScript in UFT on Page

In UFT,  we can run java script on a page using RunScript method as shown below. This can be very useful to perform operation on a page/element in the page through Java script.


Browser(...).Page(...).runscript("javascript statement")

XPath Object Identification in UFT descriptive programming

UFT also supports XPATH and css together with descriptive programming, object repository and DOM for object Identification.

Xpath stands for Xml Path. Below are some XPath examples to be used with UFT. Xpath and css are most widely used object identification way in selenium also.


Xpath examples:

Id: 

Browser(...).Page(...).weblink("xpath:=//a[@id='linkuft']").click

Attribute Value:

Browser(...).Page(...).weblink("xpath:=//a[@Atttribute='goodclass']").click

text:

Browser(...).Page(...).weblink("xpath:=//a[text()='UFT']").click 

partial attribute value

Browser(...).Page(...).weblink("xpath:=//a[starts-with(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[contains(@attribute,'goodclass']").click

Browser(...).Page(...).weblink("xpath:=//a[ends-with(@attribute,'goodclass']").click


To know details on what is CSS and XPath and how to capture CSS or xpath of an element. refer to

XPath and CSS for selenium/UFT

We can use tools like firebug/firepath or IE developer tool to identify the xpath/css of an element.

xpath is really useful when element is not identified diretly based on Object repository properties and used to
identify an element based on relative element existence based on other elements in the tree.

WebTables in UFT - 10 Key points

1. WebTable or html grid are integral part of html pages and a lot of application data is organised in WebTables. QTP provides different methods to interact with the webtable in the web application. In this remaining article, we will discuss key points to interact with the webtables. 
Below image shows how a webTable is divided into column and rows and data can be extracted from cell in the web table.


2. Verify if the table exist in the application
istbleExist=Browser("qaaqtp").Page("title:=.*").WebTable("name:= DataTable").exist

3. In case the table exist in the Page, we can get the count of rows and columns in the application as shown below:

iRowCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:= DataTable").RowCount
'' for each of the  row, get the column count for each row
For rownum=1 to iRowCnt
 iColCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ColumnCount(rownum) 
 MsgBox iColCnt
Next

4. Now we know the number of rows and columns in the table, we can extract cell information using the code below:
CellData= Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").GetCellData(rownum,colcnt)

5. We can perform action on object of specific type in a cell in the webTable based on the cell
ibtnCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable")
.ChildItemCount(4,3,"WebButton")
This will get the number of child items in a particular cell of particular type.

6. This will click on the 2nd  webbutton in row 4 and column 3 of the webtable.
Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(4,3,"WebButton",1).click

7. Using HTML DOM also, we can get count of objects in a webtable
ielemCnt = Browser("Google").Page("title:=.*").WebTable("name:=DataTable").object.getElementsbyTagName(strTagName).length

8. We can get row count of element based on the cell text as below:
irownum = object.GetRowWithCellText ("text to search",columnnum, startfromrownum)

9. We can work with webtable together with dynamic descriptive programming as shown below:
Set objDesc = Description.Create
objDesc("micclass").value = "WebElement"
objDesc("html tag").value = "TD"
Set childobjdesc=Browser("Google").Page("title:=.*").WebTable("name:=DataTable")ChildObjects(objDesc)

10. Using ChildItemCount and childItem, we can extract information from webTable as shown below:

Public Function findObjectinWebTable(strobjType,iRow,iCol)
 ''get child count of specific object type
 oChildCnt=Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItemCount(iRow,iCol,strobjType)
 If oChildCnt >0
  ''Perform action based on object type
  Set ChldItem = Browser("qaautmationqtp").Page("title:=.*").WebTable("name:=DataTable").ChildItem(iRow,iCol,strobjType,0)
 If (strobjType = "Link" or strobjType ="WebEdit") Then
  ChldItm.Click
  ElseIf(stobjType = "WebCheckBox") Then
  ChldItm.Set "ON"
 End If
End Function