Skip to content

Commit 8c844eb

Browse files
committed
Click Link with modifier
1 parent 9de9609 commit 8c844eb

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

atest/acceptance/keywords/click_element_modifier.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Click Element Modifier CTRL
88
Click Element Button modifier=CTRL
99
Element Text Should Be output CTRL click
1010

11+
Click Link Modifier CTRL
12+
Click Link link text modifier=CTRL
13+
Element Text Should Be output CTRL click
14+
[Teardown] Close Popup Window
15+
1116
Click Element Modifier ALT
1217
Click Element Button alt
1318
Element Text Should Be output ALT click
@@ -33,3 +38,8 @@ Click Element Wrong Modifier
3338
Initialize Page
3439
Reload Page
3540
Element Text Should Be output initial output
41+
42+
Close Popup Window
43+
Select Window myName timeout=5s
44+
Close Window
45+
Select Window MAIN timeout=5s

src/SeleniumLibrary/keywords/element.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,23 @@ def click_image(self, locator):
536536
element.click()
537537

538538
@keyword
539-
def click_link(self, locator):
539+
def click_link(self, locator, modifier=False):
540540
"""Clicks a link identified by ``locator``.
541541
542542
See the `Locating elements` section for details about the locator
543543
syntax. When using the default locator strategy, links are searched
544544
using ``id``, ``name``, ``href`` and the link text.
545+
546+
See the `Click Element` keyword for details about the
547+
``modifier`` argument.
548+
549+
The ``modifier`` argument is new in SeleniumLibrary 3.3
545550
"""
546-
self.info("Clicking link '%s'." % locator)
547-
self.find_element(locator, tag='link').click()
551+
if is_falsy(modifier):
552+
self.info("Clicking link '%s'." % locator)
553+
self.find_element(locator, tag='link').click()
554+
else:
555+
self._click_with_modifier(locator, 'link', modifier)
548556

549557
@keyword
550558
def click_element(self, locator, modifier=False):
@@ -573,14 +581,15 @@ def click_element(self, locator, modifier=False):
573581
self.info("Clicking element '%s'." % locator)
574582
self.find_element(locator).click()
575583
else:
576-
self._click_with_modifier(locator, modifier)
584+
self._click_with_modifier(locator, None, modifier)
577585

578-
def _click_with_modifier(self, locator, modifier):
586+
def _click_with_modifier(self, locator, tag, modifier):
587+
self.info("Clicking element '%s' with %s." % (locator, modifier))
579588
modifier = self.parse_modifier(modifier)
580589
action = ActionChains(self.driver)
581590
for item in modifier:
582591
action.key_down(item)
583-
action.click(self.find_element(locator))
592+
action.click(self.find_element(locator, tag=tag))
584593
for item in modifier:
585594
action.key_up(item)
586595
action.perform()

0 commit comments

Comments
 (0)