Table of Contents

Class RxPath

Namespace
Ranorex.Core
Assembly
Ranorex.Core.dll

Represents a RanoreXPath.

public class RxPath : ICloneable, IComparable<RxPath>
Inheritance
RxPath
Implements
Inherited Members

Remarks

RanoreXPath is modeled after W3C XPath and allows easy identification/searching/filtering of web elements and navigation in web documents. For detailed usage, please refer to the user guide and to the RanoreXPath examples.

Constructors

RxPath(string)

Creates a new RanoreXPath instance, using the supplied path.

public RxPath(string path)

Parameters

path string

The path to be represented by this instance.

Exceptions

RxPathException

Thrown if the path is not valid.

ArgumentNullException

If path is null.

Fields

DefaultWeightFilterThreshold

The weight threshold which determines whether an attribute is used in generated RxPaths.

public const int DefaultWeightFilterThreshold = 100

Field Value

int

LabelWeightFilterThreshold

The weight threshold which determines whether an attribute is used in element labels.

public const int LabelWeightFilterThreshold = 10

Field Value

int

Root

Represents the RxPath for the root element.

public static readonly RxPath Root

Field Value

RxPath

Properties

BuildOptions

Settings which allow tweaking the PathBuildMode.StepCostReduce algorithm.

public static PathBuildOptions BuildOptions { get; set; }

Property Value

PathBuildOptions

DataProvider

The data provider to use for resolving variables.

public IDataProvider DataProvider { get; set; }

Property Value

IDataProvider

DefaultSearchTimeout

The timeout used when elements are searched by assigning a path to an element variable (implicit cast operator).

public static Duration DefaultSearchTimeout { get; set; }

Property Value

Duration

Examples

The timeout value set to this property is used for searching when implicitly casting a path (in its string representation) to an element variable:

Element elem = "pathToElem";

Remarks

This property is equivalent to DefaultSearchTimeout.

IsAbsolute

Gets or sets a value indicating whether this instance is absolute.

public bool IsAbsolute { get; set; }

Property Value

bool

true if this instance is absolute; otherwise, false.

Length

The number of location steps contained in the RxPath.

public int Length { get; }

Property Value

int

LocationSteps

Gets or sets the location steps of this path.

public IList<LocationStep> LocationSteps { get; set; }

Property Value

IList<LocationStep>

The location steps.

MaxMatchTextLen

The maximum length to use for attribute values that have a TruncationLength of -1 when building paths. Longer attribute values are truncated at the next word boundary (if available) using StartsWith expressions.

public static int MaxMatchTextLen { get; set; }

Property Value

int

Methods

BuildElementPath(Element, Element, PathBuildMode)

Builds a RanoreXPath for a given element.

public static RxPath BuildElementPath(Element relativeParent, Element element, PathBuildMode mode)

Parameters

relativeParent Element

The ancestor element to which the path should be relative to. If this parameter is null, an absolute path is built.

element Element

The node to build the path for.

mode PathBuildMode

The path building mode. This basically controls the degree of optimization applied to the path.

Returns

RxPath

The path of the specified element relative to the specified parent element.

BuildElementPath(Element, Element, PathBuildMode, bool)

Builds a RanoreXPath for a given element.

public static RxPath BuildElementPath(Element relativeParent, Element element, PathBuildMode mode, bool forceRobustPath)

Parameters

relativeParent Element

The ancestor element to which the path should be relative to. If this parameter is null, an absolute path is built.

element Element

The node to build the path for.

mode PathBuildMode

The path building mode. This basically controls the degree of optimization applied to the path.

forceRobustPath bool

Specifies if building robuts path sholub be forced.

Returns

RxPath

The path of the specified element relative to the specified parent element.

CalcElementScore(Element, out CostInfo)

Calculates a score for an individual element used for determining the best RxPath layer/step selection.

public static int CalcElementScore(Element e, out RxPath.CostInfo rawCost)

Parameters

e Element

The element.

rawCost RxPath.CostInfo

Detailed cost values.

Returns

int

The cost value, higher is better.

ChangePrefix(RxPath, RxPath, RxPath)

Changes a given prefix of an RxPath to a new prefix.

public static RxPath ChangePrefix(RxPath path, RxPath oldPrefix, RxPath newPrefix)

Parameters

path RxPath

The path to change.

oldPrefix RxPath

The old prefix.

newPrefix RxPath

The new prefix.

Returns

RxPath

The path with the changed prefix.

Exceptions

RxPathException

If oldPrefix is not a prefix of the supplied path.

ChangePrefix(RxPath, RxPath, RxPath, bool)

Changes a given prefix of an RxPath to a new prefix.

public static RxPath ChangePrefix(RxPath path, RxPath oldPrefix, RxPath newPrefix, bool fastNoCheck)

Parameters

path RxPath

The path to change.

oldPrefix RxPath

The old prefix.

newPrefix RxPath

The new prefix.

fastNoCheck bool

Determines whether the existing prefixes are checked or not.

Returns

RxPath

The path with the changed prefix.

Exceptions

RxPathException

If oldPrefix is not a prefix of the supplied path.

Clone()

Creates a clone of the path.

public object Clone()

Returns

object

The cloned path.

CompareTo(RxPath)

Compares the current path with another path.

public int CompareTo(RxPath other)

Parameters

other RxPath

A path to compare with this path.

Returns

int

A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:

ValueMeaning
Less than zeroThis instance is less than other.
ZeroThis instance is equal to other.
Greater than zeroThis instance is greater than other.

Concat(RxPath, RxPath)

Concatenates two paths.

public static RxPath Concat(RxPath left, RxPath right)

Parameters

left RxPath

The first part of the new path.

right RxPath

The second part of the new path.

Returns

RxPath

The new path resulting from concatenating both input paths.

ConvertToCanonicalAndChain(IList<IPredicate>)

Returns a list of predicates iff the preds can be represented as a flat list of predicates.

public static IList<ComparisonPredicate> ConvertToCanonicalAndChain(IList<IPredicate> preds)

Parameters

preds IList<IPredicate>

The predicates to convert.

Returns

IList<ComparisonPredicate>

A flat list of predicates.

Equals(object)

Compares an RxPath to an object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare to.

Returns

bool

True if the object is an RxPath and the paths are exactly the same.

Escape(string)

Escapes string values for use within RxPath literals.

public static string Escape(string literal)

Parameters

literal string

The value to escape.

Returns

string

The escaped value.

ExtractCommonPrefix(IList<RxPath>)

Extracts the longest common prefix from a list of RxPaths.

public static RxPath ExtractCommonPrefix(IList<RxPath> paths)

Parameters

paths IList<RxPath>

A list of paths to extract the prefix from.

Returns

RxPath

The longest common prefix of the specified paths.

Remarks

It is not allowed to mix relative and absolute paths in the list.

GetCapabilityForTailNodeTest()

Map the RxPath nodetest name expression to a capability.

public Capability GetCapabilityForTailNodeTest()

Returns

Capability

The best matching capability or Role.Unknown.

GetHashCode()

Calculates a hash value for the RxPath.

public override int GetHashCode()

Returns

int

The hash value.

GetParentPath(RxPath)

Returns a path which applies to parent elements of an element with the specified path.

public static RxPath GetParentPath(RxPath path)

Parameters

path RxPath

The path to create the parent path from.

Returns

RxPath

Returns a path which applies to parent elements of an element with the specified path.

GetPrefixPath(RxPath, int)

Returns a path with the specified number of prefix steps

public static RxPath GetPrefixPath(RxPath path, int len)

Parameters

path RxPath

The path to create the parent path from.

len int

The number of steps for the prefix.

Returns

RxPath

Returns a path with the specified prefix length.

GetRxPathTokens(string, out bool, out string, out int)

Gets the tokens which form an RxPath.

public static IList<RxPathToken> GetRxPathTokens(string queryPath, out bool syntaxOk, out string errorMessage, out int errorPosition)

Parameters

queryPath string

The query path.

syntaxOk bool

Set to true if the sytnax of the RxPath is valid.

errorMessage string

The error message (if there was a syntax error).

errorPosition int

The error position (if there was a syntax error).

Returns

IList<RxPathToken>

A list of tokens.

Invert(RxPath)

Inverts the specified path.

public static RxPath Invert(RxPath path)

Parameters

path RxPath

The path to invert.

Returns

RxPath

The inverted path.

Remarks

Inverse path work like that: A = B.Find(P) results in B = A.Find(P^-1)

IsPrefixOf(RxPath)

Determines whether the path is a prefix of the specified path.

public bool IsPrefixOf(RxPath path)

Parameters

path RxPath

The path.

Returns

bool

true if the path is prefix of the specified path; otherwise, false.

IsSimilar(RxPath, RxPath, out int, IDataProvider)

Determines whether two paths are similar. Per definition, paths are similar if they could yield an intersecting set of result elements.

public static bool IsSimilar(RxPath a, RxPath b, out int warnCount, IDataProvider provider)

Parameters

a RxPath

The first path.

b RxPath

The second path.

warnCount int

The warn count is set to the number of significant differences both paths have (but are not a contradiction per se).

provider IDataProvider

The data provider to use to resolve variable values.

Returns

bool

true if the specified the paths are similar; otherwise, false.

Parse(string)

Parses a string into an RxPath.

public static RxPath Parse(string path)

Parameters

path string

The string instance to convert.

Returns

RxPath

The corresponding RxPath.

Exceptions

RxPathException

Thrown if the path is not valid.

ArgumentNullException

If path is null.

RemovePrefix(RxPath, RxPath, bool)

Removes a given prefix from a specific path.

public static RxPath RemovePrefix(RxPath path, RxPath prefix, bool fastNoCheck)

Parameters

path RxPath

The path to remove the prefix from.

prefix RxPath

The prefix to remove.

fastNoCheck bool

Assumes that the supplied prefix is valid.

Returns

RxPath

The path without the prefix.

Exceptions

RxPathException

If prefix is not a prefix of the supplied path.

ToResolvedString()

Converts the RxPath to its string representation, with the variables resolved to their current values.

public string ToResolvedString()

Returns

string

The RxPath as string.

Remarks

To correctly resolve the variables, an active DataProviderContext is needed.

ToString()

Converts the RxPath to its string representation.

public override string ToString()

Returns

string

The RxPath as string.

ToStringSteps()

Creates a list of strings where each location step in the RxPath corresponds to one string.

public string[] ToStringSteps()

Returns

string[]

The RxPath as string.

TryCreate(string, out RxPath)

Tries to create an RxPath instance.

public static bool TryCreate(string path, out RxPath rxPath)

Parameters

path string

The path to be represented by the rxPath instance.

rxPath RxPath

When this method returns, contains the created RxPath instance or a null reference if creating the RxPath failed.

Returns

bool

true if creating the RxPath instance succeeded, otherwise false.

Unescape(string)

Unescapes string values used within RxPath literals.

public static string Unescape(string literal)

Parameters

literal string

The value to unescape.

Returns

string

The unescaped value.

Operators

operator ==(RxPath, RxPath)

Implements the operator ==.

public static bool operator ==(RxPath left, RxPath right)

Parameters

left RxPath

The left.

right RxPath

The right.

Returns

bool

The result of the operator.

implicit operator RxPath(string)

Implicitly converts a string to an RxPath.

public static implicit operator RxPath(string path)

Parameters

path string

The string instance to convert.

Returns

RxPath

The corresponding RxPath.

Exceptions

RxPathException

Thrown if the path is not valid.

ArgumentNullException

If path is null.

operator !=(RxPath, RxPath)

Implements the operator !=.

public static bool operator !=(RxPath left, RxPath right)

Parameters

left RxPath

The left.

right RxPath

The right.

Returns

bool

The result of the operator.