Search code examples
vbscripthp-uft

How can I run UFT automation scripts without closing the existing browser sessions?


I have UFT automation scripts in which objects are captured with creation time 0. but when I run the script if there are already some browser windows open, UFT obviously fails to identify the objects in the newly opened window as the creation time doesn't match.how can we overcome this without closing the existing sessions of browsers?

I have tried closing the previous sessions so that browser window opened by the system gets creation time as 0 which would match the object properties thus object identification is successful. But there are instances where I don't want the existing browser sessions to be closed. i have an idea of changing the creation time of the objects during run time, but not sure how it can be achieved.

SystemUtil.Run "iexplore.exe", URL_TST3

Browser("Tivoli Policy Director").Page("Tivoli Policy Director").sync

If Browser("Tivoli Policy Director").Page("Tivoli Policy Director").WebEdit("username").exist(1) Then
    Browser("Tivoli Policy Director").Page("Tivoli Policy Director").WebEdit("username").Set "L104894"
    Browser("Tivoli Policy Director").Page("Tivoli Policy Director").WebEdit("password").Set "Password90"
    Browser("Tivoli Policy Director").Page("Tivoli Policy Director").WebButton("Login").Click
End If

Expected: Need object identification to be successful Actual: UFT fails to identify the object


Solution

  • Here is a simple approach. (Untested)

    We know that though we open only one chrome instance, there are more than 1 process running in the task manager. So we will get the number of that instances from task list and then update the browser index in OR.

    Run the below command in cmd using UFT (Change the browser name accordingly).

    ' chrome.exe - chrome
    ' firefox.exe - firefox
    ' iexplore.exe - internet explorer (IE)
    
    tasklist | find /I /C "iexplore.exe"
    

    Get the output and update the browser index in the OR using SetTOProperty