Accessing Object Frames in Chrome and Edge

Applies to TestComplete 15.47, last modified on January 20, 2023

The information in this topic applies both to cross-platform and classic web tests.

Webpages may use frames to present a piece of content separate from the rest of the page content. Typically, frames are implemented with the iframe element. In older web applications, they can also be implemented with the frameset and frame elements that are currently obsolete.

For security reasons, most of modern web browsers allow only same-origin content in frames. If frame content has a different origin from the parent page’s origin, the browser will disallow accessing the content. This security restriction helps preventing the malicious access to sensitive data. However, it also prevents TestComplete from accessing the content of frames on tested webpages running in Chrome and Edge browsers.

To access the frame content in Chrome or Edge, disable the same origin security restriction in the web browser. To do this:

  1. Make sure that the SitePerProcess policy is not enabled in the browser. You can get the list of policies applied to your web browser:

    • In Chrome, on the chrome://policy page.

    • In Edge, on the edge://policy page.

    Note: If the policy is hidden, select the Show policies with no value check box at the top of the page.

  2. Run the browser with the following command-line arguments specified:

    • --disable-web-security - Enables testing webpages that use cross-origin frames.

    • --user-data-dir=<ProfilePath> - Specifies a folder that stores the user profile data.

      You can get information on existing profiles:

      • In Chrome, on the chrome://version page.

      • In Edge, on the edge://version page.

    • --disable-site-isolation-trials - Allows setting up the browser security.

    These command-line arguments impair the browser security. We do not recommend using them unless required by your testing needs.

Disabling the same origin security restriction from tests

You can automate running Edge or Chrome with required command-lime arguments specified directly from your tests. To set command-line arguments, you can use the Browsers.Item().RunOptions property.

In keyword tests
  1. In your test, add the Call Object Method operation before the operation that launches your Chrome or Edge browser.

  2. TestComplete will open the Operation Parameters wizard.

  3. On the first page of the wizard, specify the object that provides access to your web browser:

    • For Chrome, it is Browsers.Item("chrome").

    • For Edge, it is Browsers.Item("Edge").

  4. On the next page of the wizard, select the RunOptions [set] method.

  5. On the last page of the wizard, enter the command-line parameters to pass to the selected web browser. For example:

    --disable-web-security --user-data-dir="C:\Users\<User_Name>\AppData\Local\Microsoft\Edge\User Data\Profile 1" --disable-site-isolation-trials
  6. Click Finish to close the wizard and save the changes.

Running a web browser with same origin security restriction disabled

Click the image to enlarge it.

In script tests

Use the Browsers.Item().RunOptions property to set command-line arguments to pass to your web browser before launching it. For example, the code snippet below shows how to launch Chrome with cross-origin content enabled:

JavaScript, JScript

function Sample_Run_Browser()
{
  Browsers.Item("chrome").RunOptions = "--disable-web-security --user-data-dir=\"C:\\Users\\Tester\\AppData\\Local\\Google\\Chrome\\User Data\\Default\" --disable-site-isolation-trials";
  Browsers.Item(btChrome).Run("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe");
  // …
}

Python

def Sample_Run_Browser():
  Browsers.Item["chrome"].RunOptions = "--disable-web-security --user-data-dir=\"C:\\Users\\Tester\\AppData\\Local\\Google\\Chrome\\User Data\\Default\" --disable-site-isolation-trials"
  Browsers.Item[btChrome].Run("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe")
  # …

VBScript

Sub Sample_Run_Browser()
  Browsers.Item("chrome").RunOptions = "--disable-web-security --user-data-dir="C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials"
  Browsers.Item(btChrome).Run("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe")
  ' …
End Sub

DelphiScript

procedure Sample_Run_Browser();
begin
  Browsers.Item('chrome').RunOptions := '--disable-web-security --user-data-dir="C:\Users\Tester\AppData\Local\Google\Chrome\User Data\Default" --disable-site-isolation-trials';
  Browsers.Item[btChrome].Run('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe');
  // …
end;

C++Script, C#Script

function Sample_Run_Browser()
{
  Browsers["Item"]("chrome")["RunOptions"] = "--disable-web-security --user-data-dir=\"C:\\Users\\Tester\\AppData\\Local\\Google\\Chrome\\User Data\\Default\" --disable-site-isolation-trials";
  Browsers["Item"](btChrome)["Run"]("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe");
  // …
}

See Also

How To
Preparing Chrome for Web Testing
Preparing Edge for Web Testing

Highlight search results