Element Interface¶
Warning
This is auto-generated interface documentation for the abstract Element class.
This is essential for providing a comprehensive overview of all available methods for the Element object.
For the actual signature, please refer to dyatel.base.element.Element.
Note
All of these methods will work in the same way for Group class instances, which represent a collection of elements.
The Element class is a fundamental building block for creating Page Object Models (POM) in web testing.
It provides a comprehensive set of methods that allow you to interact with various web page elements which be found below.
- class dyatel.base.element.Element(*args, **kwargs)¶
Element object crossroad. Should be defined as Page/Group class variable
- property driver_wrapper: DriverWrapper¶
Retrieves the driver wrapper instance.
- Returns:
The current
DriverWrapperinstance that assigned for this object.- Return type:
- set_text(text: str, silent: bool = False) Element¶
Clear the current input field and type the provided text.
- send_keyboard_action(action: str | PlaywrightKeys) Element¶
Send a keyboard action to the current element (e.g., press a key or shortcut).
- Parameters:
action (str or
KeyboardKeys) – The keyboard action to perform.- Returns:
- wait_visibility_without_error(*, timeout: int | float = 2.5, silent: bool = False) Element¶
Wait for the element to become visible, without raising an error if it does not.
Note: The method requires the use of named arguments.
Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
Wait for the element to become hidden, without raising an error if it does not.
Note: The method requires the use of named arguments.
Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_for_text(expected_text: str | None = None, *, timeout: int | float = 10, silent: bool = False) Element¶
Wait for the presence of a specific text in the current element, or for any non-empty text.
Note: The method requires the use of named arguments except
expected_text.Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_for_value(expected_value: str | None = None, *, timeout: int | float = 10, silent: bool = False) Element¶
Wait for a specific value in the current element, or for any non-empty value.
Note: The method requires the use of named arguments except
expected_value.Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_enabled(*, timeout: int | float = 10, silent: bool = False) Element¶
Wait for the element to become enabled and/or clickable.
Note: The method requires the use of named arguments.
Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_disabled(*, timeout: int | float = 10, silent: bool = False) Element¶
Wait for the element to become disabled.
Note: The method requires the use of named arguments.
Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_for_size(expected_size: Size, *, timeout: int | float = 10, silent: bool = False) Element¶
Wait until element size will be equal to given
SizeobjectNote: The method requires the use of named arguments except
expected_size.Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_elements_count(expected_count: int, *, timeout: int | float = 10, silent: bool = False) Element¶
Wait until the number of matching elements equals the expected count.
Note: The method requires the use of named arguments except
expected_count.Selenium & Playwright:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- property all_elements: List[Element]¶
Returns a list of all matching elements.
- Returns:
A list of wrapped
Elementobjects.
- is_visible(check_displaying: bool = True, silent: bool = False) bool¶
Checks is the current element’s top-left corner or bottom-right corner is visible on the screen.
- is_fully_visible(check_displaying: bool = True, silent: bool = False) bool¶
Check is current element top left corner and bottom right corner visible on current screen
- save_screenshot(file_name: str, screenshot_base: bytes | Image | None = None, convert_type: str | None = None) Image¶
Saves a screenshot of the element.
- Parameters:
file_name (str) – Path or filename for the screenshot.
screenshot_base (
bytes,PIL.Image.Image) – Screenshot binary or image to use (optional).convert_type (str) – Image conversion type before saving (optional).
- Returns:
- execute_script(script: str, *args) Any¶
Executes a JavaScript script on the element.
- Parameters:
script (str) – JavaScript code to be executed, referring to the element as
arguments[0].args – Additional arguments for the script, that appear in script as
arguments[1]arguments[2]etc.
- Returns:
typing.Anyresult from the script.
- assert_screenshot(filename: str = '', test_name: str = '', name_suffix: str = '', threshold: int | float | None = None, delay: int | float | None = None, scroll: bool = False, remove: Element | List[Element] | None = None, fill_background: str | bool = False, cut_box: CutBox | None = None, hide: Element | List[Element] | None = None) None¶
Asserts that the given screenshot matches the currently taken screenshot.
- Parameters:
filename (str) – The full name of the screenshot file. If empty - filename will be generated based on test name &
Elementnameargument & platform.test_name (str) – The custom test name for generated filename. If empty - it will be determined automatically.
name_suffix (str) – A suffix to add to the filename. Useful for distinguishing between positive and negative cases for the same
Elementduring one test.threshold (Optional[int or float]) – The acceptable threshold for comparing screenshots. If
None- takes default threshold or calculate its automatically based on screenshot size.delay (Optional[int or float]) – The delay in seconds before taking the screenshot. If
None- takes default delay.scroll (bool) – Whether to scroll to the element before taking the screenshot.
remove (Optional[Element or List[Element]]) –
Elementto remove from the screenshot. Can be a single element or a list of elements.fill_background (Optional[str or bool]) – The color to fill the background. If
True, uses a default color (black). If astr, uses the specified color.cut_box (Optional[CutBox]) – A CutBox specifying a region to cut from the screenshot. If
None, no region is cut.hide (Optional[Element or List[Element]]) –
Elementto hide in the screenshot. Can be a single element or a list of elements.
- Returns:
- soft_assert_screenshot(filename: str = '', test_name: str = '', name_suffix: str = '', threshold: int | float | None = None, delay: int | float | None = None, scroll: bool = False, remove: Element | List[Element] | None = None, fill_background: str | bool = False, cut_box: CutBox | None = None, hide: Element | List[Element] | None = None) Tuple[bool, str]¶
Compares the currently taken screenshot to the expected screenshot and returns a result.
- Parameters:
filename (str) – The full name of the screenshot file. If empty - filename will be generated based on test name &
Elementnameargument & platform.test_name (str) – The custom test name for generated filename. If empty - it will be determined automatically.
name_suffix (str) – A suffix to add to the filename. Useful for distinguishing between positive and negative cases for the same
Elementduring one test.threshold (Optional[int or float]) – The acceptable threshold for comparing screenshots. If
None- takes default threshold or calculate its automatically based on screenshot size.delay (Optional[int or float]) – The delay in seconds before taking the screenshot. If
None- takes default delay.scroll (bool) – Whether to scroll to the element before taking the screenshot.
remove (Optional[Element or List[Element]]) –
Elementto remove from the screenshot.fill_background (Optional[str or bool]) – The color to fill the background. If
True, uses a default color (black). If astr, uses the specified color.cut_box (Optional[CutBox]) – A CutBox specifying a region to cut from the screenshot. If
None, no region is cut.hide –
Elementto hide in the screenshot. Can be a single element or a list of elements.
- Returns:
- get_element_info(element: Element | None = None) str¶
Retrieves detailed logging information for the specified element.
- click(*, force_wait: bool = True, **kwargs) Element¶
Clicks on the element.
Selenium/Appium:
Selenium Safari using js click instead.
- Parameters:
kwargs – compatibility arg for playwright
Playwright:
- Parameters:
kwargs – any kwargs params from source API
- Returns:
- click_in_alert() Element¶
Perform a click on an element inside an alert box (Mobile only). Note: Automatically switches to native context of the browser.
- Returns:
- click_outside(x: int = -5, y: int = -5) Element¶
Perform a click outside the current element, by default 5px left and above it.
- property driver: WebDriver | WebDriver | Page¶
Retrieves the source driver instance, which could be a Selenium, Appium, or Playwright driver.
- Returns:
Current source driver that assigned for this object, which is either
selenium.webdriver.remote.webdriver.WebDriverorappium.webdriver.webdriver.WebDriverorplaywright.sync_api.Pageinstance.
- property element: WebElement | WebElement | Locator¶
Returns a source element object, depending on the current driver in use.
- Returns:
selenium.webdriver.remote.webelement.WebElementorappium.webdriver.webelement.WebElementorplaywright.sync_api.Locator
- get_attribute(attribute: str, silent: bool = False) str¶
Retrieve a specific attribute from the current element.
- get_rect() dict¶
Retrieve the size and position of the element as a dictionary.
- Returns:
dict- A dictionary {‘x’, ‘y’, ‘width’, ‘height’} of the element.
- hover_outside(x: int = 0, y: int = -5) Element¶
Hover the mouse outside the current element, by default 5px above it.
Checks if the element is hidden.
- property location: Location¶
Get the location of the current element, including the x and y coordinates.
- Returns:
Location- An object representing the element’s position.
- log(message: str, level: str = 'info') None¶
Logs a message with detailed context in the following format:
# Format [time][level][driver_index][module][function:line] <message> # Example [Aug 14][16:04:22.767][I][2_driver][play_element.py][is_displayed:328] Check visibility of "Mouse page"
- property screenshot_base: bytes¶
Returns the binary screenshot data of the element.
- Returns:
bytes- screenshot binary
- screenshot_image(screenshot_base: bytes | None = None) Image¶
Returns a
PIL.Image.Imageobject representing the screenshot of the web element. Appium iOS: Take driver screenshot and crop manually element from it
- scroll_into_view(block: ScrollTo = 'center', behavior: ScrollTypes = 'instant', sleep: int | float = 0, silent: bool = False) Element¶
Scrolls the element into view using a JavaScript script.
- Parameters:
- Returns:
- property size: Size¶
Get the size of the current element, including width and height.
- Returns:
Size- An object representing the element’s dimensions.
- type_slowly(text: str, sleep_gap: float = 0.05, silent: bool = False) Element¶
Types text into the element slowly with a delay between keystrokes.
- wait_availability(*, timeout: int = 10, silent: bool = False) Element¶
Waits until the element becomes available in DOM tree.
Note: The method requires the use of named arguments.
Selenium:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
Waits until the element becomes hidden. Note: The method requires the use of named arguments.
Selenium:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.
- wait_visibility(*, timeout: int = 10, silent: bool = False) Element¶
Waits until the element becomes visible. Note: The method requires the use of named arguments.
Selenium:
Applied
wait_condition()decorator integrates a 0.1 seconds delay for each iteration during the waiting process.
Appium:
Applied
wait_condition()decorator integrates an exponential delay (starting at 0.1 seconds, up to a maximum of 1.6 seconds) which increases with each iteration during the waiting process.