Skip to main content

Interactions

Explore here available methods how you can interact with your pages and components. All methods are fluent in mind, allowing you to continue interaction with the subject under focus.

ya.SearchPage.Open().SearchInput.Fill("yapoml");

All components are automatically awaited to be presented on the page before any interaction, providing a possibility to specify expectations explicitly.

Page

Methods

Open

Navigates to the page. Available only if the page has defined url property.

Home.page.yaml
url: some/relative/path
ya.HomePage.Open();

It requires base url to be specified if url path is relative.

driver.Ya(opts => opts.WithBaseUrl("https://example.com")).HomePage.Open();

url might have segments and query parameters

url:
path: /users/{userId}
query: # or params
- p1
- p2
ya.HomePage.Open("123", p2: "any value") // navigates to /users/123?p2=any%20value

Segments are required. If you need skip some particular segment from the url path, you can put null. Query parameters are always optional.

Component

Properties

IsDisplayed

Indicates whether a component is visible on the page or not. Returns true if the element is displayed, and false if the element is hidden or not present.

Useful for verifying the visibility of components that may change dynamically based on user actions or page conditions. For example, you can use it to check if a dropdown menu is expanded or collapsed, or if a modal dialog is open or closed. It does not check if the component is within the viewport or not. It only checks if the element is rendered on the page, regardless of its position or size. Look at IsInView property if you need to check whether the component is within the viewport.

Usage

bool visible = ya.HomePage.SearchButton.IsDisplayed;
note

It doesn't expect a component exists in DOM. It only returns true if a component is found in DOM and visible. Otherwise, it returns false.

IsEnabled

Used to indicate whether a component can respond to user interactions or not. It returns a boolean value: true if the element is enabled, and false if the element is disabled.

For example, you can use it to check if a checkbox is checked or unchecked, or if a text field is editable or read-only.

Usage

bool enabled = ya.HomePage.SearchButton.IsEnabled;

Text

Gets the visible text of a component. It returns a string value that represents the inner text of the element. For example, you can use it to check if a label displays the correct message, or if a paragraph contains the expected text.

Usage

string text = ya.HomePage.SearchButton.Text;
note

This property may not work as expected for some components that do not have any visible text content. For example, input elements (<input>) do not have any inner text, so they will return an empty string for this property. To get the value of an input element, you may need to use the Attributes.Value property.

Attributes…

Gets the value of an attribute of a component as a string. It can also retrieve component properties, such as an anchor tag’s href attribute.

For example, you can use it to check if an input element has a value attribute that matches the expected input, or if an image element has an alt attribute that describes the image.

Usage

string value = ya.HomePage.SearchInput.Attributes["value"];
tip

Well-known attributes are accessible shortly.

var value = ya.HomePage.SearchInput.Attributes.Value;
// or
var href = ya.HomePage.Logo.Attributes.Href;

Styles…

Gets the value of a CSS property of a component as a string. It can be used to retrieve the computed style of a component, such as its color, font-size, or display.

For example, you can use it to check if an element has a certain background color, or if an element is visible or hidden by its display property.

Usage

string color = ya.HomePage.SearchButton.Styles["color"];
tip

Well-known styles are accessible shortly.

string color = ya.HomePage.SearchButton.Styles.Color;
// or
float opacity = ya.HomePage.SearchButton.Styles.Opacity;

IsFocused

Indicates whether a component currently has logical focus or not. It returns a boolean value: true if the component has focus, and false if the component does not have focus.

Usage

bool hasFocus = ya.HomePage.SearchInput.IsFocused;

IsInView

Indicates whether a component currently is partially visible within viewport or not. It returns a boolean value: true if the component is in viewport, and false if the component is not.

Usage

bool isInViewport = ya.HomePage.SearchInput.IsInView;

Methods

Click

Simulates a mouse click on a component. It can be used to interact with buttons, links, checkboxes, radio buttons, and other clickable components on a page.

Usage

ya.HomePage.SearchButton.Click();

Or with specified offset.

ya.HomePage.SearchButton.Click(x: 20, y: 30);

The Click method performs a left-click by default. To perform other click actions see ContextClick, DoubleClick, DragAndDrop, etc.

DoubleClick

Simulates a mouse double click on a component. It can be used to interact with elements that require a double click to launch specific functions, such as opening a file, selecting a word of text, etc.

Usage

ya.HomePage.Pane.DoubleClick();

ContextClick

Simulates a mouse right click on a component. It can be used to interact with elements that show a context menu when right clicked, such as opening a link in a new tab, copying text.

Usage

ya.HomePage.Pane.ContextClick();

Type

Sends a sequence of keystrokes to a component. It is useful for entering text, selecting options, or performing keyboard shortcuts. For example, you can use it to type a query in a search box, choose a value from a dropdown menu, or press the enter key.

Usage

ya.HomePage.SearchInput.Type("yapoml");

Clear

Clears the text from a component. It is useful for deleting the existing text before entering new text. For example, you can use it to erase a query in a search box, or clear a password field.

Usage

ya.HomePage.SearchInput.Clear();

Fill

Clears and types the new text into a component. It is useful when you need to make sure that a component is cleared before typing new text.

Usage

ya.HomePage.SearchInput.Fill("yapoml");

Hover

Simulates a mouse hover over a component. It is useful for triggering events that depend on the mouse cursor position, such as displaying tooltips, menus, or pop-ups. For example, you can use it to hover over a link to see its URL, or hover over a button to see its description.

Usage

ya.HomePage.SearchButton.Hover();

Focus

Sets the focus on a component. It is useful for activating the component or preparing it for user input. For example, you can use it to focus on a text field before typing, or focus on a checkbox before clicking.

Usage

ya.HomePage.SearchInput.Focus();

Blur

Removes the focus from a component. It is useful for deactivating the component or triggering events that depend on the focus state, such as validation or formatting. For example, you can use it to blur a text field after typing, or blur a dropdown menu after selecting an option.

Usage

ya.HomePage.SearchInput.Blur();

DragAndDrop

Performs a drag and drop action on a component. It is useful for moving a component from one location to another, such as rearranging items, sorting lists, or uploading files. For example, you can use it to drag an image from a gallery and drop it into a trash bin, or drag a file from a folder and drop it into an upload box.

Usage

var homePage = ya.HomePage;

homePage.SearchButton.DragAndDrop(homePage.Trash);

ScrollIntoView

Scrolls the web page until a component is visible. It is useful for accessing components that are not in the current viewport, such as hidden or lazy-loaded components. For example, you can use it to scroll to the bottom of a page to see the footer, or scroll to a specific section of a page to see its content.

Usage

ya.HomePage.SearchButton.ScrollIntoView();

GetScreenshot

Gets a screenshot of the current state of the component in PNG format.

Usage

ya.HomePage.SearchButton.GetScreenshot();