Unable to execute javascript function/sentence with RunScript method of Page Object

The web application I'm testing has its Front End developed in Angular and I use UFT version 23.4. I want to execute the RunScript method on the Page object to execute the javascript function/statement that reloads the page (window.location.reload();). The browser I'm using is Chrome, and JavaScript is enabled in settings.

I have tried defining the statement directly and encapsulating it in a function or using the eval function and invoking it from a (.js) file, but I have not achieved the expected result in any way:

Browser("MyBrowser").Page("MyPage").RunScript "window.location.reload();"

Browser("MyBrowser").Page("MyPage").RunScript "eval(window.location.reload(););"

Browser("MyBrowser").Page("MyPage").RunScript "(function() { window.location.reload(); })();"


Why aren't my JavaScript executions working from UFT? Is there something I haven't taken into account?

  • 0  

    Hello,

    Is your script working properly on the previous UFT version?

    If you are using v3 extension, you may try with v2 extension.

    BTW, I tried the below one on google.com using v3 extension and it works fine.

    Browser("MyBrowser").Page("MyPage").RunScript "(function() { window.location.reload(); })();"

    BR,

    Angel

  • 0 in reply to   

    Hi,

    I have tried both Chrome extension version v2 and v3, and the result is the same, the page does not reload. Other JavaScript functions/statements works fine, such as clicking on an element of the page.

    Browser("MyBrowser").Page("MyPage").RunScript "(function() {var buttons = document.getElementsByClassName("myButtonClass");buttons[0].click();})();"

  • 0   in reply to 

    Please open a support ticket for further investigation.

    I am curious if you want to reload the page, why not use Brwoser.refresh method?

  • 0 in reply to   

    To interact with the browser objects once the chrome.exe process is executed:

    SistemUtil.Run "chrome.exe"


    I need to reload/refresh the browser/page, otherwise UFT doesn't interact with the browser objects.

     Brwoser.refresh method doesn't work for my Web APP, that's why I was trying to execute the reload function in JavaScript.


    The only solution that works is to create Windows Object and send F5:

    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.AppActivate("Chrome")
    objShell.SendKeys "{F5}"