ToUrl Method (Window Objects)

Applies to TestComplete 14.72, last modified on January 20, 2021

Description

The ToUrl method is only added to window objects that correspond to WebBrowser controls and to Internet Explorer’s. It loads the page specified by the URL parameter in Internet Explorer, Firefox or WebBrowser control and returns the Page object that corresponds to the loaded 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

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

URL

Specifies the URL of the page to be opened in the browser.

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 corresponds to the newly loaded web page.

Remarks

  • If the method navigates to a web page successfully, it posts an event message to the test log.

  • If the method cannot navigate to a web page, it fails and posts an error message to the test log.

  • The ToUrl method is only added to window objects that correspond to WebBrowser controls. This method is an analogue of the Page.ToUrl method. However, it lets you load web pages in a browser without having to obtain the Page object that provides access to web pages.

  • When recording actions that open a web page, TestComplete automatically transforms them into the appropriate calls to 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.

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

Example

The code below determines whether a page was loaded successfully.

JavaScript, JScript

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

Python

Page = w.ToUrl("www.MyURL.com")
if (not Page.Exists):
  # Error!

VBScript

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

DelphiScript

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

C++Script, C#Script

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

See Also

Default Web Testing
Page Object
URL Property
ToUrl Method (Browser Objects)
Navigate to Web Pages

Highlight search results