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
elementElementThe element to create the adapter for.
Exceptions
- NullReferenceException
If
elementisnull.- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.
Fields
disableTransitionsJSFunctionName
public const string disableTransitionsJSFunctionName = "disableTransitions"
Field Value
enableTranstitionsJSFunctionName
public const string enableTranstitionsJSFunctionName = "enableTransitions"
Field Value
hidePositionFixedJSFunctionName
public const string hidePositionFixedJSFunctionName = "hidePositionFixed"
Field Value
restorePositionFixedJSFunctionName
public const string restorePositionFixedJSFunctionName = "restorePositionFixed"
Field Value
scrollToPointJSFunctionName
public const string scrollToPointJSFunctionName = "scrollToPoint"
Field Value
Properties
Browser
The browser form that this document is shown in.
public virtual Form Browser { get; }
Property Value
BrowserName
The name of the browser that this document is shown in.
public virtual string BrowserName { get; }
Property Value
BrowserVersion
The version of the browser that this document is shown in.
public virtual string BrowserVersion { get; }
Property Value
Domain
The domain name part of the PageUrl.
public virtual string Domain { get; }
Property Value
FullScreen
True if the browser is in full screen mode.
public virtual bool FullScreen { get; set; }
Property Value
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
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
Page
The page part of the PageUrl.
public virtual string Page { get; }
Property Value
PageUrl
The url of the web document.
public virtual string PageUrl { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
Path
The path part of the PageUrl.
public virtual string Path { get; }
Property Value
ProcessId
The process id of the browser window.
public virtual string ProcessId { get; }
Property Value
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
Methods
CaptureFullPageScreenshot(CapturePageFlags)
Captures a full page screen shot of the WebDocument.
public Bitmap CaptureFullPageScreenshot(WebDocument.CapturePageFlags flags = CapturePageFlags.None)
Parameters
flagsWebDocument.CapturePageFlagsFlags 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
redrawRetriesintNumber of internal redraw retries.
compareThresholddoubleThe compare threshold for scroll/redraw detection.
compareDelayintThe internal compare delay for scroll/redraw detection.
flagsWebDocument.CapturePageFlagsFlags controlling the behavior of the capture operation.
onBeforeScrollCallbackAction<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
duplicatesTextstringA 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
codestringThe 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
elementElementThe element to convert.
Returns
- WebDocument
The WebDocument.
Exceptions
- ArgumentNullException
If
elementisnull.- 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
pathstringThe search path.
Returns
- WebDocument
The WebDocument.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- RxPathException
If the specified
pathis 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
urlstringThe 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
urlstringThe URL to navigate to.
waitForLoadedboolSpecifies 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
urlstringThe URL to navigate to.
waitForLoadedboolSpecifies whether this method should block until the new document has been loaded.
timeoutDurationSpecifies 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
timeoutelapsed 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
timeoutDurationSpecifies the maximum time to wait for the document to be loaded.
Exceptions
- ArgumentOutOfRangeException
If the timeout is negative.
- RanorexException
If the specified
timeoutexpired 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
elementElementThe element to convert.
Returns
- WebDocument
The WebDocument.
Exceptions
- ArgumentNullException
If
elementisnull.- 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
pathstringThe search path.
Returns
- WebDocument
The WebDocument.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- RxPathException
If the specified
pathis not valid.- ElementNotFoundException
If no element is found.
- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.