Running scripts on a page

Sometimes, when testing web applications, there arises a need to launch some script on the page.

The easiest way to do so is launching the script directly from the address bar of the browser.

How to do it...

To launch the script in the browser, it is necessary to:

  1. First of all, write the script which transfers current URL location to a specific address:
    var br = Aliases.browser;
    br.ToUrl("http://smartbear.com");
    var page = br.pageMain;
  2. Now we will launch the script that will execute JavaScript code on the page:
    page.NavigateTo("javascript: alert('A message from script'),");
  3. In the result, the browser window will have the following message appear:
    How to do it...

How it works...

To execute the JavaScript code in the browser window, it is sufficient to input the code into the address bar of the browser as a string, placing the keyword javascript: before the pasted code.

The method NavigateTo lets us open the page specified by the URL parameter. Unlike the ToUrl method, method NavigateTo doesn't return any value after the page is loaded.

In our case, the method of NavigateTo is used to execute the JavaScript code on the page.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.32.222