How to verify the position of an object using UFT on a webpage

We can verify the position of an object using UFT by utilizing two properties named clientWidth and offSetLeft. Suppose that we have two elements namely element1 and element2 and we have to verify if element2 is in the extreme right of element1.

Logic behind verifying position of an object using UFT

To understand the logic behind this, first, we need to understand the two properties we are going to work on and what are they for.

  • clientWidth – This gives the width of the object
  • offsetLeft – This gives how much screen width is in the left side of the object

The principle of verifying this is if element2 leaves as much screen width as to contain the element1 width, it means that element 2 is in the extreme right of element 1.

Example code to verify position of an object using UFT and vbscript
'============================================================================================
'Function Name	- VerifyElementPosition
'Arguments	- Element1, Element2, Position
'Returns	- Nothing, verification
'Purpose	- to check if a webelement Element 2 is in the extreme right of Element 1
'Description	- to check if a webelement Element 2 is in the extreme right of Element 1
'============================================================================================
	
	
Function VerifyElementPosition(Element1, Element2, Position)
    width1= Element1.getROProperty("clientWidth")
    width2= Element2.getROproperty("clientWidth")
    offsetLeft2= Element2.getROproperty("offsetLeft")
    offsetdiff= width1-width2

    Select Case ucase(Position)
      Case "EXTREME RIGHT"
        If offsetLeft2=offsetdiff Then
          reporter.ReportEvent micPass, Element2.tostring & " should be in " &Position & " of "&   Element1.tostring ," "
        else
          reporter.ReportEvent micFail, Element2.tostring & " should be in " &Position & " of "&   Element1.tostring ," "
    End If
    End Select

    CaptureScreenshot "PositionVerification"
	
End Function

You may also read


Discover more from Automation Script

Subscribe to get the latest posts sent to your email.

Related Posts