Search code examples
vbscripthp-ufthp-quality-centeruft-api

Replacing portion of a URL in HPE UFT / VBscript


So I am trying to get a script to work that will obtain the current URL of the open tab, replace a portion of the URL, and enter in/navigate to the new URL which has the replaced text.

I'm struggling with the replace function as well as how to launch the edited URL in the current tab.

Here a rough idea of how I think it should look. If this worked worked it would open up a new browser with the new URL but I'd like it to be on the tab I'm currently in.

Would I need to crate an object for the result of the replace function?

If I were currently at

abc123.UZ.com/xaxsxa

I'd like to go to the page

xyz789.UZ.com/xaxsxa

Code:

 Browser("Edge").Page("Loan#").WebButton("LoanConditions").Click
 Browser("Edge").Page("Loan#).GetROProperty("url") 
 Result = Browser("Edge").Page("Loan#").GetROProperty("url")
 replace (Result,"abc123","xyz789")
 Systemutil.Run "Chrome.exe", "Result"

Solution

  • Use the Navigate method of the Browser object.

    You just need to replace the last 2 lines with:

    Result = replace(Result,"abc123","xyz789")
    Browser("Edge").Navigate Result
    

    Update(Based on the issue mentioned in Comments):

    Try this code. This is still untested by me. So, let me know if it works for you.

    set odesc = Description.create
    odesc("micclass").value = "Browser"
    intBefore = Desktop.Childobjects(odesc).count
    Browser("Edge").Page("Loan#").WebButton("LoanConditions").Click
    Browser("Edge").Page("Loan#").Sync
    intAfter = Desktop.Childobjects(odesc).count
    if intAfter = intBefore + 1 then
        intIndex = intAfter-1
        set objBro = Desktop.Childobjects(odesc).item(intIndex)
        Result = objBro.getRoProperty("url")
        Result = replace(Result,"abc123","xyz789")
        objBro.Navigate Result
    end if