How to verify presence of scrollbar using UFT

We can verify presence of scrollbar using UFT very easily when we have a scrollbar present on the screen. In order to verify the presence of scrollbar we need to validate two properties of any object i.e. clientheight and scrollheight. You can get these properties of any object using the inbuilt method getROProperty of UFT/QTP.

Logic behind verifying presence of scrollbar

Clientheight represents the height of object visible and scrollheight represents height of object with scrolling. So if scrolling height is greater than the visible height then we can conclude that there is a scrollbar present on the secreen.

This can be utilized to verify presence of scrollbar in those objects where there is content hidden behind a scrollbar and it appears when we scroll. For example- any text area containing plain text

Example code to verify presence of scrollbar using UFT
'''****************************************************************************************
'Function Name: fnValidateScrollBar
'Description:	Validates presence of a scrollbar in an object
'Arguements:	objScroll= object where scrollbar has to be verified, 
'             TC= (Test case name number anything to attach with file name)
'''****************************************************************************************


Function fnValidateScrollBar(objScroll,TC)
	
  ncH1= objScroll.getROProperty("clientHeight")
  nsH1= objScroll.getROProperty("scrollHeight")

  If strcomp(ncH1,"")=0 Then
  ncH1= objScroll.Object.clientHeight

  nsH1= objScroll.Object.scrollHeight

  End If
  If nsH1>=ncH1 Then
    reporter.ReportEvent micPass, TC & " ScrollBar validation",TC & "ScrollBar is enabled"
    else
    reporter.ReportEvent micFail, TC & " ScrollBar validation",TC & "ScrollBar is disabled"
  End If
		
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.