Table of Contents

Class WebDocument

Namespace
Ranorex
Assembly
Ranorex.Plugin.Web.dll

The element represents a web document opened as a browser tab or embedded in another application.

public class WebDocument : Adapter, IAdapter
Inheritance
WebDocument
Implements
Inherited Members

Constructors

WebDocument()

Creates a new WebDocument adapter instance. This constructor is used internally by the Ranorex Core Framework for performance issues!

protected WebDocument()

WebDocument(Element)

Creates a new WebDocument adapter instance.

public WebDocument(Element element)

Parameters

element Element

The element to create the adapter for.

Exceptions

NullReferenceException

If element is null.

CapabilityNotSupportedException

If the element does not support the capabilities required by this adapter.

Fields

disableTransitionsJSFunctionName

public const string disableTransitionsJSFunctionName = "disableTransitions"

Field Value

string

enableTranstitionsJSFunctionName

public const string enableTranstitionsJSFunctionName = "enableTransitions"

Field Value

string

hidePositionFixedJSFunctionName

public const string hidePositionFixedJSFunctionName = "hidePositionFixed"

Field Value

string

restorePositionFixedJSFunctionName

public const string restorePositionFixedJSFunctionName = "restorePositionFixed"

Field Value

string

scrollToPointJSFunctionName

public const string scrollToPointJSFunctionName = "scrollToPoint"

Field Value

string

Properties

Browser

The browser form that this document is shown in.

public virtual Form Browser { get; }

Property Value

Form

BrowserName

The name of the browser that this document is shown in.

public virtual string BrowserName { get; }

Property Value

string

BrowserVersion

The version of the browser that this document is shown in.

public virtual string BrowserVersion { get; }

Property Value

string

Domain

The domain name part of the PageUrl.

public virtual string Domain { get; }

Property Value

string

FullScreen

True if the browser is in full screen mode.

public virtual bool FullScreen { get; set; }

Property Value

bool

Exceptions

SetAttributeFailedException

Thrown if setting the attribute value failed.

MaxScreenshotHeight

Maximum height of screen-shot captured. Default is 32768. Property is used in CaptureFullPageScreenshot(CapturePageFlags) method.

public static int MaxScreenshotHeight { get; set; }

Property Value

int

MaxScreenshotWidth

Maximum width of screen-shot captured. Default is 8192. Property is used in CaptureFullPageScreenshot(CapturePageFlags) method.

public static int MaxScreenshotWidth { get; set; }

Property Value

int

Page

The page part of the PageUrl.

public virtual string Page { get; }

Property Value

string

PageUrl

The url of the web document.

public virtual string PageUrl { get; set; }

Property Value

string

Exceptions

SetAttributeFailedException

Thrown if setting the attribute value failed.

Path

The path part of the PageUrl.

public virtual string Path { get; }

Property Value

string

ProcessId

The process id of the browser window.

public virtual string ProcessId { get; }

Property Value

string

RequiredCapabilities

Capabilities required by the adapter implementation.

protected override string[] RequiredCapabilities { get; }

Property Value

string[]

State

The current load state of the web document (invalid, loading, loaded, interactive, complete).

public virtual string State { get; }

Property Value

string

Methods

CaptureFullPageScreenshot(CapturePageFlags)

Captures a full page screen shot of the WebDocument.

public Bitmap CaptureFullPageScreenshot(WebDocument.CapturePageFlags flags = CapturePageFlags.None)

Parameters

flags WebDocument.CapturePageFlags

Flags controlling the behavior of the capture operation.

Returns

Bitmap

A bitmap with the full page screen-shot.

Remarks

Uses default values for redrawRetries (5), compareThreshold( .999) and compareDelay (500). The CSS modification flags are currently experimental.

CaptureFullPageScreenshot(int, double, int, CapturePageFlags, Action<WebDocument, int, int>)

Captures a full page screen-shot of the WebDocument.

public Bitmap CaptureFullPageScreenshot(int redrawRetries, double compareThreshold, int compareDelay, WebDocument.CapturePageFlags flags = CapturePageFlags.None, Action<WebDocument, int, int> onBeforeScrollCallback = null)

Parameters

redrawRetries int

Number of internal redraw retries.

compareThreshold double

The compare threshold for scroll/redraw detection.

compareDelay int

The internal compare delay for scroll/redraw detection.

flags WebDocument.CapturePageFlags

Flags controlling the behavior of the capture operation.

onBeforeScrollCallback Action<WebDocument, int, int>

An optional callback which is called before the page is scrolled while capturing.

Returns

Bitmap

A bitmap with the full page screen-shot.

Remarks

The CSS modification flags are currently experimental.

CheckDuplicateElementIds(out string)

Checks the WebDocument (not including child frames) for duplicate element 'id' attributes.

public bool CheckDuplicateElementIds(out string duplicatesText)

Parameters

duplicatesText string

A list of id's found which are used on multiple html elements.

Returns

bool

Returns 'True' if no duplicates were found.

Close()

Closes the browser window or tab.

public virtual void Close()

Exceptions

ActionFailedException

Thrown if invoking the action failed.

ExecuteScript(string)

Executes javascript code inside the web document.

public virtual string ExecuteScript(string code)

Parameters

code string

The javascript code chunk.

Returns

string

The JS return statement expression result.

Exceptions

ActionFailedException

Thrown if invoking the action failed.

FromElement(Element)

Converts an Element to an instance of this class.

public static WebDocument FromElement(Element element)

Parameters

element Element

The element to convert.

Returns

WebDocument

The WebDocument.

Exceptions

ArgumentNullException

If element is null.

CapabilityNotSupportedException

If the element does not support the capabilities required by this adapter.

FromPath(string)

Converts a string to an instance of this class by searching the root.

public static WebDocument FromPath(string path)

Parameters

path string

The search path.

Returns

WebDocument

The WebDocument.

Remarks

The DefaultSearchTimeout is used to search for the specified path.

Exceptions

ArgumentNullException

If path is null.

RxPathException

If the specified path is not valid.

ElementNotFoundException

If no element is found.

CapabilityNotSupportedException

If the element does not support the capabilities required by this adapter.

GetHtml()

Retrieves the HTML source text of the web document.

public virtual string GetHtml()

Returns

string

The HTML source text.

Exceptions

ActionFailedException

Thrown if invoking the action failed.

Navigate(string)

Instructs the web browser associated with this web document to navigate to the specified url.

[DefaultAction]
public void Navigate(string url)

Parameters

url string

The URL to navigate to.

Remarks

An infinite timeout is used to wait for the document to be loaded.

The url may be absolute (http://www.host.com/path/to/webpage) or relative (path/to/webpage) to the current URL of the web document.

Navigate(string, bool)

Instructs the web browser associated with this web document to navigate to the specified url.

public void Navigate(string url, bool waitForLoaded)

Parameters

url string

The URL to navigate to.

waitForLoaded bool

Specifies whether this method should block until the new document has been loaded.

Remarks

An infinite timeout is used when waiting for the document to be loaded.

The url may be absolute (http://www.host.com/path/to/webpage) or relative (path/to/webpage) to the current URL of the web document.

Navigate(string, bool, Duration)

Instructs the web browser associated with this web document to navigate to the specified url.

public void Navigate(string url, bool waitForLoaded, Duration timeout)

Parameters

url string

The URL to navigate to.

waitForLoaded bool

Specifies whether this method should block until the new document has been loaded.

timeout Duration

Specifies the maximum time to wait for the document to be loaded.

Remarks

The url may be absolute (http://www.host.com/path/to/webpage) or relative (path/to/webpage) to the current URL of the web document.

Exceptions

ArgumentOutOfRangeException

If the timeout is negative.

RanorexException

If the specified timeout elapsed before the document is loaded.

WaitForDocumentLoaded()

Waits until the document is loaded.

public void WaitForDocumentLoaded()

Remarks

Calling this method is equivalent to calling WaitForDocumentLoaded(Duration) with the timeout parameter set to MaxValue.

WaitForDocumentLoaded(Duration)

Waits until the document is loaded or the timeout has expired.

public void WaitForDocumentLoaded(Duration timeout)

Parameters

timeout Duration

Specifies the maximum time to wait for the document to be loaded.

Exceptions

ArgumentOutOfRangeException

If the timeout is negative.

RanorexException

If the specified timeout expired before the document is loaded.

Operators

implicit operator WebDocument(Element)

Implicitly converts an Element to an instance of this class.

public static implicit operator WebDocument(Element element)

Parameters

element Element

The element to convert.

Returns

WebDocument

The WebDocument.

Exceptions

ArgumentNullException

If element is null.

CapabilityNotSupportedException

If the element does not support the capabilities required by this adapter.

implicit operator WebDocument(string)

Implicitly converts a string to an instance of this class by searching the root.

public static implicit operator WebDocument(string path)

Parameters

path string

The search path.

Returns

WebDocument

The WebDocument.

Remarks

The DefaultSearchTimeout is used to search for the specified path.

Exceptions

ArgumentNullException

If path is null.

RxPathException

If the specified path is not valid.

ElementNotFoundException

If no element is found.

CapabilityNotSupportedException

If the element does not support the capabilities required by this adapter.