Skip to content

Commit 74204ec

Browse files
JonKoseraaltat
authored andcommitted
Added action-chain click option (#1469)
Fixes #1463
1 parent 8cb5986 commit 74204ec

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

atest/acceptance/keywords/click_element.robot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Double Click Element Error
3636
[Setup] Go To Page "javascript/click.html"
3737
Double Click Element id:öööö
3838

39+
Click Element Action Chain
40+
[Tags] NoGrid
41+
[Documentation]
42+
... LOB 1:1 INFO Clicking 'singleClickButton' using an action chain.
43+
... LOG 2:5 DEBUG GLOB: *actions {"actions": [{*
44+
Click Element singleClickButton action_chain=True
45+
Element Text Should Be output single clicked
46+
3947
*** Keywords ***
4048
Initialize Page
4149
[Documentation] Initialize Page

atest/acceptance/keywords/click_element_modifier.robot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Click Element Wrong Modifier
4242
... ValueError: 'FOOBAR' modifier does not match to Selenium Keys
4343
... Click Element Button Foobar
4444

45+
Click Element Action Chain and modifier
46+
[Documentation] LOG 2:1 INFO Clicking element 'Button' with CTRL.
47+
Click Element Button modifier=CTRL action_chain=True
48+
Element Text Should Be output CTRL click
49+
4550
*** Keywords ***
4651
Initialize Page
4752
Reload Page
@@ -50,4 +55,4 @@ Initialize Page
5055
Close Popup Window
5156
Select Window myName timeout=5s
5257
Close Window
53-
Select Window MAIN timeout=5s
58+
Select Window MAIN timeout=5s

src/SeleniumLibrary/keywords/element.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def click_link(self, locator, modifier=False):
571571
self._click_with_modifier(locator, ['link', 'link'], modifier)
572572

573573
@keyword
574-
def click_element(self, locator, modifier=False):
574+
def click_element(self, locator, modifier=False, action_chain=False):
575575
"""Click the element identified by ``locator``.
576576
577577
See the `Locating elements` section for details about the locator
@@ -586,18 +586,36 @@ def click_element(self, locator, modifier=False):
586586
[https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.ALT|ALT key]
587587
. If ``modifier`` does not match to Selenium Keys, keyword fails.
588588
589+
If ``action_chain`` argument is true, see `Boolean arguments` for more
590+
details on how to set boolean argument, then keyword uses ActionChain
591+
based click instead of the <web_element>.click() function. If both
592+
``action_chain`` and ``modifier`` are defined, the click will be
593+
performed using ``modifier`` and ``action_chain`` will be ignored.
594+
589595
Example:
590-
| Click Element | id:button | | # Would click element without any modifiers. |
591-
| Click Element | id:button | CTRL | # Would click element with CTLR key pressed down. |
592-
| Click Element | id:button | CTRL+ALT | # Would click element with CTLR and ALT keys pressed down. |
596+
| Click Element | id:button | | # Would click element without any modifiers. |
597+
| Click Element | id:button | CTRL | # Would click element with CTLR key pressed down. |
598+
| Click Element | id:button | CTRL+ALT | # Would click element with CTLR and ALT keys pressed down. |
599+
| Click Element | id:button | action_chain=True | # Clicks the button using an Selenium ActionChains |
593600
594601
The ``modifier`` argument is new in SeleniumLibrary 3.2
602+
The ``action_chain`` argument is new in SeleniumLibrary 4.1
595603
"""
596-
if is_falsy(modifier):
604+
if is_truthy(modifier):
605+
self._click_with_modifier(locator, [None, None], modifier)
606+
elif is_truthy(action_chain):
607+
self._click_with_action_chain(locator)
608+
else:
597609
self.info("Clicking element '%s'." % locator)
598610
self.find_element(locator).click()
599-
else:
600-
self._click_with_modifier(locator, [None, None], modifier)
611+
612+
def _click_with_action_chain(self, locator):
613+
self.info("Clicking '%s' using an action chain." % locator)
614+
action = ActionChains(self.driver)
615+
element = self.find_element(locator)
616+
action.move_to_element(element)
617+
action.click()
618+
action.perform()
601619

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

0 commit comments

Comments
 (0)