Esempio n. 1
0
    def double_click_element(self, locator):
        """Double clicks the element identified by ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info("Double clicking element '%s'." % locator)
        element = self.find_element(locator)
        action = ActionChains(self.driver)
        action.double_click(element).perform()
Esempio n. 2
0
    def mouse_down_on_image(self, locator):
        """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')
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Esempio n. 3
0
    def mouse_down_on_link(self, locator):
        """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')
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Esempio n. 4
0
    def drag_and_drop(self, locator, target):
        """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)
        target = self.find_element(target)
        action = ActionChains(self.driver)
        action.drag_and_drop(element, target).perform()
Esempio n. 5
0
 def _click_with_modifier(self, locator, tag, modifier):
     self.info("Clicking %s '%s' with %s." %
               (tag if tag[0] else 'element', locator, 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])
     action.click(element)
     for item in modifier:
         action.key_up(item)
     action.perform()
Esempio n. 6
0
 def _click_with_action_chain(self, locator):
     self.info("Clicking '%s' using an action chain." % locator)
     action = ActionChains(self.driver)
     element = self.find_element(locator)
     action.move_to_element(element)
     action.click()
     action.perform()
Esempio n. 7
0
    def mouse_down(self, locator):
        """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("Simulating Mouse Down on element '%s'." % locator)
        element = self.find_element(locator)
        action = ActionChains(self.driver)
        action.click_and_hold(element).perform()
Esempio n. 8
0
    def scroll_element_into_view(self, locator):
        """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)
        # Try/except can be removed when minimum required Selenium is 4.0 or greater.
        try:
            ActionChains(self.driver).move_to_element(element).perform()
        except AttributeError:
            self.debug('Workaround for Selenium 3 bug.')
            element = element.wrapped_element
            ActionChains(self.driver).move_to_element(element).perform()
Esempio n. 9
0
    def mouse_up(self, locator):
        """Simulates releasing the left mouse button on the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info("Simulating Mouse Up on element '%s'." % locator)
        element = self.find_element(locator)
        ActionChains(self.driver).release(element).perform()
Esempio n. 10
0
    def mouse_out(self, locator):
        """Simulates moving the mouse away from the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info("Simulating Mouse Out on element '%s'." % locator)
        element = self.find_element(locator)
        size = element.size
        offsetx = (size['width'] / 2) + 1
        offsety = (size['height'] / 2) + 1
        action = ActionChains(self.driver)
        # Try/except can be removed when minimum required Selenium is 4.0 or greater.
        try:
            action.move_to_element(element)
        except AttributeError:
            self.debug('Workaround for Selenium 3 bug.')
            element = element.wrapped_element
            action.move_to_element(element)
        action.move_by_offset(offsetx, offsety)
        action.perform()
Esempio n. 11
0
    def mouse_over(self, locator):
        """Simulates hovering the mouse over the element ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.
        """
        self.info("Simulating Mouse Over on element '%s'." % locator)
        element = self.find_element(locator)
        action = ActionChains(self.driver)
        # Try/except can be removed when minimum required Selenium is 4.0 or greater.
        try:
            action.move_to_element(element).perform()
        except AttributeError:
            self.debug('Workaround for Selenium 3 bug.')
            element = element.wrapped_element
            action.move_to_element(element).perform()
Esempio n. 12
0
    def drag_and_drop_by_offset(self, locator, xoffset, yoffset):
        """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)
        action = ActionChains(self.driver)
        action.drag_and_drop_by_offset(element, int(xoffset), int(yoffset))
        action.perform()
Esempio n. 13
0
 def _press_keys(self, locator, parsed_keys):
     if is_truthy(locator):
         element = self.find_element(locator)
     else:
         element = None
     for parsed_key in parsed_keys:
         actions = ActionChains(self.driver)
         special_keys = []
         for key in parsed_key:
             if self._selenium_keys_has_attr(key.original):
                 special_keys = self._press_keys_special_keys(
                     actions, element, parsed_key, key, special_keys)
             else:
                 self._press_keys_normal_keys(actions, element, key)
         for special_key in special_keys:
             self.info('Releasing special key %s.' % special_key.original)
             actions.key_up(special_key.converted)
         actions.perform()
Esempio n. 14
0
 def open_context_menu(self, locator):
     """Opens the context menu on the element identified by ``locator``."""
     element = self.find_element(locator)
     action = ActionChains(self.driver)
     action.context_click(element).perform()
Esempio n. 15
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("Clicking element '%s' at coordinates x=%s, y=%s." %
                  (locator, xoffset, yoffset))
        element = self.find_element(locator)
        action = ActionChains(self.driver)
        # Try/except can be removed when minimum required Selenium is 4.0 or greater.
        try:
            action.move_to_element(element)
        except AttributeError:
            self.debug('Workaround for Selenium 3 bug.')
            element = element.wrapped_element
            action.move_to_element(element)
        action.move_by_offset(xoffset, yoffset)
        action.click()
        action.perform()