Skip to content

Commit 61e5259

Browse files
committed
Click button with modifier
1 parent 8c844eb commit 61e5259

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

atest/acceptance/keywords/click_element_modifier.robot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Click Link Modifier CTRL
1313
Element Text Should Be output CTRL click
1414
[Teardown] Close Popup Window
1515

16+
Click Button Modifier CTRL
17+
Click Button Click me! modifier=CTRL
18+
Element Text Should Be output CTRL click
19+
1620
Click Element Modifier ALT
1721
Click Element Button alt
1822
Element Text Should Be output ALT click

src/SeleniumLibrary/keywords/element.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,26 @@ def get_vertical_position(self, locator):
507507
return self.find_element(locator).location['y']
508508

509509
@keyword
510-
def click_button(self, locator):
510+
def click_button(self, locator, modifier=False):
511511
"""Clicks button identified by ``locator``.
512512
513513
See the `Locating elements` section for details about the locator
514514
syntax. When using the default locator strategy, buttons are
515515
searched using ``id``, ``name`` and ``value``.
516+
517+
See the `Click Element` keyword for details about the
518+
``modifier`` argument.
519+
520+
The ``modifier`` argument is new in SeleniumLibrary 3.3
516521
"""
517-
self.info("Clicking button '%s'." % locator)
518-
element = self.find_element(locator, tag='input', required=False)
519-
if not element:
520-
element = self.find_element(locator, tag='button')
521-
element.click()
522+
if is_falsy(modifier):
523+
self.info("Clicking button '%s'." % locator)
524+
element = self.find_element(locator, tag='input', required=False)
525+
if not element:
526+
element = self.find_element(locator, tag='button')
527+
element.click()
528+
else:
529+
self._click_with_modifier(locator, 'button', modifier)
522530

523531
@keyword
524532
def click_image(self, locator):
@@ -584,7 +592,7 @@ def click_element(self, locator, modifier=False):
584592
self._click_with_modifier(locator, None, modifier)
585593

586594
def _click_with_modifier(self, locator, tag, modifier):
587-
self.info("Clicking element '%s' with %s." % (locator, modifier))
595+
self.info("Clicking %s '%s' with %s." % (tag if tag else 'element', locator, modifier))
588596
modifier = self.parse_modifier(modifier)
589597
action = ActionChains(self.driver)
590598
for item in modifier:

0 commit comments

Comments
 (0)