OnScreenElement Methods
This method is used to clone an element when finding all instances with FindAllInstances. The returned elements are in general shallow clones of the original element, however for elements with sub-elements (e.g. LabelWithCheckbox) those should be cloned in an override.
public virtual OnScreenElement CloneForMultipleInstances()
A clone of the element.
Finds all instances of the element that are visible on the screen and returns them as a list of OnScreenElement. The returned elements all have UseCachedPosition set to true, so that the respective position is used when we interact with the element. The returned elements are in general shallow clones of the original element, however for elements with sub-elements (e.g. LabelWithCheckbox) those should be cloned in an override of the CloneForMultipleInstances method.
public IList<IEngineResult> FindAllInstances()
A list of elements corresponding to all positions where the element was found on the screen.
Exception | Condition |
When the element is not found at all. | |
Finds all instances of the element that are visible on the screen.
public IList<IEngineResult> FindAllInstances()
Exception | Condition |
When the element is not found at all. | |
Determines whether the element is currently shown on the screen, using the WaitFor method with a very short wait time.
Note: Do not use this if you expect the element to appear after an action (e.g. as verify method of another action), only if the screen is expected to be static.
Syntax:
public bool IsOnScreen()
Uses the provided IScroller (if available) to find the OnScreenElement in a scrollable area. If the element is not found at current position, scrolls to top and then down in steps.
public IEngineResult ScrollAndFindElement(
IScroller scroller,
bool throwException = true,
TimeSpan searchTime = default
)
Parameter | Description |
scroller | Type: IScroller
The scroller that shall be used to find the elemnt. Typically the scroller is a property on the screen object containing the element. |
[throwException] | |
[waitTime] | Type: TimeSpan
For how long the element should be searched before each scroll action. If not set or set to default(TimeSpan) , only 1 search is performed before scrolling again (recommended). |
Exception | Condition |
When the element is not found after scrolling through the complete range, and throwException is true or not set. |
public void SetSelectFilter(
Select select
)
Parameter | Description |
select |
Returns a string that represents this instance, usually the DisplayName. Used for logging; just use
$"{this}"
.public string ToString()
Waits for the element to appear on screen and returns an IEngineResult. If the element is found, it will call the Initialize method to initialize potential child elements that depend on the Position found by WaitFor.
By default throws an exception if the element is not found after WaitTimeInSeconds.
public virtual IEngineResult WaitFor(
bool throwException = true,
TimeSpan waitTime = default(TimeSpan)
)
Parameter | Description |
[throwException] | |
[waitTime] | Type: TimeSpan
For how long the element should be searched. If not set or set to default(TimeSpan) , the WaitTimeInSeconds property is used. |
Exception | Condition |
When the element is not found, and throwException is true or not set. |
Shorthand notation for
WaitFor(false).HasSucceeded;
Can be used as verify function without lambda operator (e.g. Buttton.Click(element.WaitForDisappear);
)
Note: This method logs, whereas WaitFor() does not log.public bool WaitForAppear()
Waits for the element to disappear from the screen. Returns false if element is still found after DisappearWaitTimeInSeconds.
Can be used as verify function without lambda operator (e.g.
Buttton.Click(element.WaitForDisappear);
)public bool WaitForAppear()
Waits for the element to disappear from the screen or any element from elements to appear.
This is often used as verify method of an interaction that closes a dialog or similar but can also show a warning instead.
Returns false if
this
element is still found after DisappearWaitTimeInSeconds and no element from elements was found. Will return the element that was found in foundElement.public bool WaitForDisappearOrOtherElement(
out OnScreenElement foundElement,
params OnScreenElement[] elements
)
Parameter | Description |
foundElement | |
elements | Type: OnScreenElement[]
A list of elements that can appear instead of this element disappearing. Typically warnings, confirmation or failure notification. |
True, if
this
element disappeared or an element from elements was found. Otherwise false.Exception | Condition |
ArgumentNullException | When elements is null or an empty list. |
protected virtual IEngineResult WaitForImpl(
TimeSpan waitTime,
ImageReference imgRef = null
)
Parameter | Description |
waitTime | |
imgRef |
Waits for a specific imageReference of the element to appear on screen and returns an IEngineResult.
This method is intended for elements like Button or Checkbox to Wait for a certain state (like inactive or checked). If imageReference is null, behaves like WaitFor(bool, TimeSpan)
If the imageReference is found, it will call the Initialize method to initialize potential child elements that depend on the Position found by WaitFor.
By default throws an exception if the element is not found after WaitTimeInSeconds.
protected virtual IEngineResult WaitFor(
ImageReference imageReference,
bool throwException = true,
TimeSpan waitTime = default(TimeSpan)
)
Parameter | Description |
imageReference | The image reference that will be used to locate the element on the screen. |
[throwException] | |
[waitTime] | Type: TimeSpan
For how long the element should be searched. If not set or set to default(TimeSpan) , the WaitTimeInSeconds property is used. |
Exception | Condition |
When the element is not found, and throwException is true or not set. |
Executes the specified interact method on the element and verifies the interaction with the verify function.
Performs RetryCount retries if the verify is not successful.
protected virtual void Do(
Action interact,
Func<bool> verify
)
Parameter | Description |
interact | |
verify |
Exception | Condition |
When verify returned false even after the retries. |
Executes the specified interact method on the element and verifies the interaction with the verify function.
Performs RetryCount retries if the verify is not successful. Before each retry, a recovery action is executed.
protected virtual void Do(
Action interact,
Func<bool> verify,
Action recovery
)
Parameter | Description |
interact | |
verify | |
recovery | Type: Action
The action that should be performed if the verify failed before doing a retry. This can be used to make sure the state of the element is the same as before the first interact (e.g. Click out to unfocus, close DropdownList, etc) |
Exception | Condition |
When verify returned false even after the retries. |
Initializes potential child controls on this Element. This method is called when WaitFor() did find the element. Has no implementation on OnScreenElement.
protected virtual void Initialize()
Last modified 10d ago