Skip to content

Commit

Permalink
Added action-chain click option (#1469)
Browse files Browse the repository at this point in the history
Fixes #1463
  • Loading branch information
JonKoser authored and aaltat committed Oct 7, 2019
1 parent 8cb5986 commit 74204ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
8 changes: 8 additions & 0 deletions atest/acceptance/keywords/click_element.robot
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ Double Click Element Error
[Setup] Go To Page "javascript/click.html"
Double Click Element id:öööö

Click Element Action Chain
[Tags] NoGrid
[Documentation]
... LOB 1:1 INFO Clicking 'singleClickButton' using an action chain.
... LOG 2:5 DEBUG GLOB: *actions {"actions": [{*
Click Element singleClickButton action_chain=True
Element Text Should Be output single clicked

*** Keywords ***
Initialize Page
[Documentation] Initialize Page
Expand Down
7 changes: 6 additions & 1 deletion atest/acceptance/keywords/click_element_modifier.robot
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Click Element Wrong Modifier
... ValueError: 'FOOBAR' modifier does not match to Selenium Keys
... Click Element Button Foobar

Click Element Action Chain and modifier
[Documentation] LOG 2:1 INFO Clicking element 'Button' with CTRL.
Click Element Button modifier=CTRL action_chain=True
Element Text Should Be output CTRL click

*** Keywords ***
Initialize Page
Reload Page
Expand All @@ -50,4 +55,4 @@ Initialize Page
Close Popup Window
Select Window myName timeout=5s
Close Window
Select Window MAIN timeout=5s
Select Window MAIN timeout=5s
32 changes: 25 additions & 7 deletions src/SeleniumLibrary/keywords/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def click_link(self, locator, modifier=False):
self._click_with_modifier(locator, ['link', 'link'], modifier)

@keyword
def click_element(self, locator, modifier=False):
def click_element(self, locator, modifier=False, action_chain=False):
"""Click the element identified by ``locator``.
See the `Locating elements` section for details about the locator
Expand All @@ -586,18 +586,36 @@ def click_element(self, locator, modifier=False):
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.ALT|ALT key]
. If ``modifier`` does not match to Selenium Keys, keyword fails.
If ``action_chain`` argument is true, see `Boolean arguments` for more
details on how to set boolean argument, then keyword uses ActionChain
based click instead of the <web_element>.click() function. If both
``action_chain`` and ``modifier`` are defined, the click will be
performed using ``modifier`` and ``action_chain`` will be ignored.
Example:
| Click Element | id:button | | # Would click element without any modifiers. |
| Click Element | id:button | CTRL | # Would click element with CTLR key pressed down. |
| Click Element | id:button | CTRL+ALT | # Would click element with CTLR and ALT keys pressed down. |
| Click Element | id:button | | # Would click element without any modifiers. |
| Click Element | id:button | CTRL | # Would click element with CTLR key pressed down. |
| Click Element | id:button | CTRL+ALT | # Would click element with CTLR and ALT keys pressed down. |
| Click Element | id:button | action_chain=True | # Clicks the button using an Selenium ActionChains |
The ``modifier`` argument is new in SeleniumLibrary 3.2
The ``action_chain`` argument is new in SeleniumLibrary 4.1
"""
if is_falsy(modifier):
if is_truthy(modifier):
self._click_with_modifier(locator, [None, None], modifier)
elif is_truthy(action_chain):
self._click_with_action_chain(locator)
else:
self.info("Clicking element '%s'." % locator)
self.find_element(locator).click()
else:
self._click_with_modifier(locator, [None, None], modifier)

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()

def _click_with_modifier(self, locator, tag, modifier):
self.info("Clicking %s '%s' with %s." % (tag if tag[0] else 'element', locator, modifier))
Expand Down

0 comments on commit 74204ec

Please sign in to comment.