Beispiel #1
0
 def open_context_menu(self, locator: Union[WebElement, str]):
     """Opens the context menu on the element identified by ``locator``."""
     element = self.find_element(locator)
     # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
     element = _unwrap_eventfiring_element(element)
     action = ActionChains(self.driver)
     action.context_click(element).perform()
Beispiel #2
0
 def _click_with_action_chain(self, locator: Union[WebElement, str]):
     self.info(f"Clicking '{locator}' using an action chain.")
     action = ActionChains(self.driver)
     element = self.find_element(locator)
     # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
     element = _unwrap_eventfiring_element(element)
     action.move_to_element(element)
     action.click()
     action.perform()
Beispiel #3
0
    def drag_and_drop(self, locator: str, target: str):
        """Drags the element identified by ``locator`` into the ``target`` element.

        The ``locator`` argument is the locator of the dragged element
        and the ``target`` is the locator of the target. See the
        `Locating elements` section for details about the locator syntax.

        Example:
        | `Drag And Drop` | css:div#element | css:div.target |
        """
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        target = self.find_element(target)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        target = _unwrap_eventfiring_element(target)
        action = ActionChains(self.driver)
        action.drag_and_drop(element, target).perform()
Beispiel #4
0
    def mouse_up(self, locator: Union[WebElement, str]):
        """Simulates releasing the left mouse button on the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info(f"Simulating Mouse Up on element '{locator}'.")
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        ActionChains(self.driver).release(element).perform()
Beispiel #5
0
    def mouse_down_on_link(self, locator: Union[WebElement, str]):
        """Simulates a mouse down event on a link identified by ``locator``.

        See the `Locating elements` section for details about the locator
        syntax. When using the default locator strategy, links are searched
        using ``id``, ``name``, ``href`` and the link text.
        """
        element = self.find_element(locator, tag="link")
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Beispiel #6
0
    def mouse_over(self, locator: Union[WebElement, str]):
        """Simulates hovering the mouse over the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info(f"Simulating Mouse Over on element '{locator}'.")
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.move_to_element(element).perform()
Beispiel #7
0
    def scroll_element_into_view(self, locator: Union[WebElement, str]):
        """Scrolls the element identified by ``locator`` into view.

        See the `Locating elements` section for details about the locator
        syntax.

        New in SeleniumLibrary 3.2.0
        """
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        ActionChains(self.driver).move_to_element(element).perform()
Beispiel #8
0
    def double_click_element(self, locator: Union[WebElement, str]):
        """Double clicks the element identified by ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info(f"Double clicking element '{locator}'.")
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.double_click(element).perform()
Beispiel #9
0
    def mouse_down_on_image(self, locator: str):
        """Simulates a mouse down event on an image identified by ``locator``.

        See the `Locating elements` section for details about the locator
        syntax. When using the default locator strategy, images are searched
        using ``id``, ``name``, ``src`` and ``alt``.
        """
        element = self.find_element(locator, tag="image")
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Beispiel #10
0
    def mouse_out(self, locator: Union[WebElement, str]):
        """Simulates moving the mouse away from the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info(f"Simulating Mouse Out on element '{locator}'.")
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        size = element.size
        offsetx = (size["width"] / 2) + 1
        offsety = (size["height"] / 2) + 1
        action = ActionChains(self.driver)
        action.move_to_element(element)
        action.move_by_offset(offsetx, offsety)
        action.perform()
Beispiel #11
0
    def mouse_down(self, locator: Union[WebElement, str]):
        """Simulates pressing the left mouse button on the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.

        The element is pressed without releasing the mouse button.

        See also the more specific keywords `Mouse Down On Image` and
        `Mouse Down On Link`.
        """
        self.info(f"Simulating Mouse Down on element '{locator}'.")
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Beispiel #12
0
 def _click_with_modifier(self, locator, tag, modifier):
     self.info(
         f"Clicking {tag if tag[0] else 'element'} '{locator}' with {modifier}."
     )
     modifier = self.parse_modifier(modifier)
     action = ActionChains(self.driver)
     for item in modifier:
         action.key_down(item)
     element = self.find_element(locator, tag=tag[0], required=False)
     if not element:
         element = self.find_element(locator, tag=tag[1])
     # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
     element = _unwrap_eventfiring_element(element)
     action.click(element)
     for item in modifier:
         action.key_up(item)
     action.perform()
Beispiel #13
0
    def drag_and_drop_by_offset(self, locator: str, xoffset: int, yoffset: int):
        """Drags the element identified with ``locator`` by ``xoffset/yoffset``.

        See the `Locating elements` section for details about the locator
        syntax.

        The element will be moved by ``xoffset`` and ``yoffset``, each of which
        is a negative or positive number specifying the offset.

        Example:
        | `Drag And Drop By Offset` | myElem | 50 | -35 | # Move myElem 50px right and 35px down |
        """
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.drag_and_drop_by_offset(element, xoffset, yoffset)
        action.perform()
Beispiel #14
0
    def click_element_at_coordinates(self, locator, xoffset, yoffset):
        """Click the element ``locator`` at ``xoffset/yoffset``.

        The Cursor is moved and the center of the element and x/y coordinates are
        calculated from that point.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info(
            f"Clicking element '{locator}' at coordinates x={xoffset}, y={yoffset}."
        )
        element = self.find_element(locator)
        # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
        element = _unwrap_eventfiring_element(element)
        action = ActionChains(self.driver)
        action.move_to_element(element)
        action.move_by_offset(xoffset, yoffset)
        action.click()
        action.perform()
Beispiel #15
0
    def press_keys(self,
                   locator: Union[WebElement, None, str] = None,
                   *keys: str):
        """Simulates the user pressing key(s) to an element or on the active browser.

        If ``locator`` evaluates as false, see `Boolean arguments` for more
        details, then the ``keys`` are sent to the currently active browser.
        Otherwise element is searched and ``keys`` are send to the element
        identified by the ``locator``. In later case, keyword fails if element
        is not found. See the `Locating elements` section for details about
        the locator syntax.

        ``keys`` arguments can contain one or many strings, but it can not
        be empty. ``keys`` can also be a combination of
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html|Selenium Keys]
        and strings or a single Selenium Key. If Selenium Key is combined
        with strings, Selenium key and strings must be separated by the
        `+` character, like in `CONTROL+c`. Selenium Keys
        are space and case sensitive and Selenium Keys are not parsed
        inside of the string. Example AALTO, would send string `AALTO`
        and `ALT` not parsed inside of the string. But `A+ALT+O` would
        found Selenium ALT key from the ``keys`` argument. It also possible
        to press many Selenium Keys down at the same time, example
        'ALT+ARROW_DOWN`.

        If Selenium Keys are detected in the ``keys`` argument, keyword
        will press the Selenium Key down, send the strings and
         then release the Selenium Key. If keyword needs to send a Selenium
        Key as a string, then each character must be separated with
        `+` character, example `E+N+D`.

        `CTRL` is alias for
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.CONTROL|Selenium CONTROL]
        and ESC is alias for
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.ESCAPE|Selenium ESCAPE]

        New in SeleniumLibrary 3.3

        Examples:
        | `Press Keys` | text_field | AAAAA          |            | # Sends string "AAAAA" to element.                                                |
        | `Press Keys` | None       | BBBBB          |            | # Sends string "BBBBB" to currently active browser.                               |
        | `Press Keys` | text_field | E+N+D          |            | # Sends string "END" to element.                                                  |
        | `Press Keys` | text_field | XXX            | YY         | # Sends strings "XXX" and "YY" to element.                                        |
        | `Press Keys` | text_field | XXX+YY         |            | # Same as above.                                                                  |
        | `Press Keys` | text_field | ALT+ARROW_DOWN |            | # Pressing "ALT" key down, then pressing ARROW_DOWN and then releasing both keys. |
        | `Press Keys` | text_field | ALT            | ARROW_DOWN | # Pressing "ALT" key and then pressing ARROW_DOWN.                                |
        | `Press Keys` | text_field | CTRL+c         |            | # Pressing CTRL key down, sends string "c" and then releases CTRL key.            |
        | `Press Keys` | button     | RETURN         |            | # Pressing "ENTER" key to element.                                                |
        """
        parsed_keys = self._parse_keys(*keys)
        if not is_noney(locator):
            self.info(f"Sending key(s) {keys} to {locator} element.")
            element = self.find_element(locator)
            # _unwrap_eventfiring_element can be removed when minimum required Selenium is 4.0 or greater.
            element = _unwrap_eventfiring_element(element)
            ActionChains(self.driver).click(element).perform()
        else:
            self.info(f"Sending key(s) {keys} to page.")
            element = None
        for parsed_key in parsed_keys:
            actions = ActionChains(self.driver)
            for key in parsed_key:
                if key.special:
                    self._press_keys_special_keys(actions, element, parsed_key,
                                                  key)
                else:
                    self._press_keys_normal_keys(actions, key)
            self._special_key_up(actions, parsed_key)
            actions.perform()