ToUrl Method (Page Objects)

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

The ToUrl method opens the page specified by the URL parameter in the web browser and returns the Page program object that corresponds to the new page. You can use the Exists property to determine if the new page was loaded successfully.

Declaration

TestObj.ToUrl(URLWaitTime)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
URL [in]    Required    String    
WaitTime [in]    Optional    Integer Default value: -1   
Result A Page object

Applies To

The method is applied to the following object:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameters:

URL

The URL to navigate to. It is recommended to specify the protocol in the URL. Otherwise, the page might not be loaded. For example, use http://www.smartbear.com rather than www.smartbear.com

If the tested web page is located on your computer, then to make your script computer-independent, use the server name rather than localhost when specifying the page’s URL, that is, for instance, use the URL http://mycomp/path/mypage.htm rather than http://localhost/path/mypage.htm. See Computer-Specific Settings for more information about this.

WaitTime

Specifies the time (in milliseconds) to wait until the browser loads the page and becomes ready to accept user input. If WaitTime is omitted, the timeout is specified by the project's Web page loading timeout option. After the specified time limit is reached, the test execution proceeds.

Result Value

A Page object that represents the new web page.

Remarks

  • To determine whether the specified web page has loaded completely, TestComplete uses the following techniques:

    The described mechanism of determining whether a web page has been downloaded completely is acceptable only for static web pages and is not effective for pages with dynamic content. For more information, see Wait For Web Pages and Waiting for Web Pages in Hybrid Mobile Applications.

  • The ToURL method uses two waiting periods:

    • First, the method waits for the web page to load for the timeout period specified by the WaitTime parameter and stops waiting when it determines that the page has been loaded completely or after the timeout elapses.

      The method also stops waiting if the loaded page displays a login dialog. In this case, you need to create test commands that simulate user actions over the dialog to closes it.

    • After the method stops waiting for the page to be loaded, it waits for the time specified by the Auto-wait timeout setting until the object hierarchy contains the desired Page object.

  • When recording actions that open a web page, TestComplete automatically transforms them into the appropriate calls of the ToUrl method. However, a method call is not inserted into the test, unless some other actions (mouse clicks, keyboard input, checkpoints, etc.) are performed over the opened page.

  • To load web pages in a browser, you can also use the Browsers.CurrentBrowser.Navigate or Browser.ToUrl method.

  • ToURL automatically sets the zoom ratio of the destination page to 100%.

  • If User Account Control (UAC) is enabled on your computer, the Page object corresponding to the current web page opened in Internet Explorer is destroyed if the ToURL method navigates to a page that belongs to another domain. Then, a new Page object that corresponds to a target page in Internet Explorer is created. If you face any issues caused by this behavior, you can do the following:

Example

The following example opens a new page and checks whether it has loaded successfully.

JavaScript, JScript

var NewPage = Page.ToUrl("www.MyURL.com");
if (! NewPage.Exists)
{
  // Error!
}

Python

NewPage = Page.ToUrl("www.MyURL.com")
if not NewPage.Exists:
  # Error!
  Log.Error("Texty text.")

VBScript

Set NewPage = Page.ToUrl("www.MyURL.com")
If Not NewPage.Exists Then
  ' Error!
End If

DelphiScript

NewPage := Page.ToUrl('www.MyURL.com');
if not NewPage.Exists then
begin
  // Error!
end;

C++Script, C#Script

var NewPage = Page["ToUrl"]("www.MyURL.com");
if (! NewPage["Exists"])
{
  // Error!
}

See Also

Default Web Testing
Navigate Method
ToUrl Method (Browser Objects)
URL Property (Page Objects)
Navigate to Web Pages
Testing Hybrid Mobile Applications

Highlight search results