Skip to content

Commit 0755340

Browse files
committed
Code refactoring
1 parent 3f81a2d commit 0755340

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed

src/SeleniumLibrary/keywords/element.py

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,46 @@ def get_vertical_position(self, locator):
506506
"""
507507
return self.find_element(locator).location['y']
508508

509+
@keyword
510+
def click_button(self, locator):
511+
"""Clicks button identified by ``locator``.
512+
513+
See the `Locating elements` section for details about the locator
514+
syntax. When using the default locator strategy, buttons are
515+
searched using ``id``, ``name`` and ``value``.
516+
"""
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+
523+
@keyword
524+
def click_image(self, locator):
525+
"""Clicks an image identified by ``locator``.
526+
527+
See the `Locating elements` section for details about the locator
528+
syntax. When using the default locator strategy, images are searched
529+
using ``id``, ``name``, ``src`` and ``alt``.
530+
"""
531+
self.info("Clicking image '%s'." % locator)
532+
element = self.find_element(locator, tag='image', required=False)
533+
if not element:
534+
# A form may have an image as it's submit trigger.
535+
element = self.find_element(locator, tag='input')
536+
element.click()
537+
538+
@keyword
539+
def click_link(self, locator):
540+
"""Clicks a link identified by ``locator``.
541+
542+
See the `Locating elements` section for details about the locator
543+
syntax. When using the default locator strategy, links are searched
544+
using ``id``, ``name``, ``href`` and the link text.
545+
"""
546+
self.info("Clicking link '%s'." % locator)
547+
self.find_element(locator, tag='link').click()
548+
509549
@keyword
510550
def click_element(self, locator, modifier=False):
511551
"""Click element identified by ``locator``.
@@ -533,14 +573,17 @@ def click_element(self, locator, modifier=False):
533573
self.info("Clicking element '%s'." % locator)
534574
self.find_element(locator).click()
535575
else:
536-
modifier = self.parse_modifier(modifier)
537-
action = ActionChains(self.driver)
538-
for item in modifier:
539-
action.key_down(item)
540-
action.click(self.find_element(locator))
541-
for item in modifier:
542-
action.key_up(item)
543-
action.perform()
576+
self._click_with_modifier(locator, modifier)
577+
578+
def _click_with_modifier(self, locator, modifier):
579+
modifier = self.parse_modifier(modifier)
580+
action = ActionChains(self.driver)
581+
for item in modifier:
582+
action.key_down(item)
583+
action.click(self.find_element(locator))
584+
for item in modifier:
585+
action.key_up(item)
586+
action.perform()
544587

545588
@keyword
546589
def click_element_at_coordinates(self, locator, xoffset, yoffset):
@@ -832,17 +875,6 @@ def _press_keys_special_keys(self, actions, element, parsed_key, key, special_ke
832875
special_keys.append(key)
833876
return special_keys
834877

835-
@keyword
836-
def click_link(self, locator):
837-
"""Clicks a link identified by ``locator``.
838-
839-
See the `Locating elements` section for details about the locator
840-
syntax. When using the default locator strategy, links are searched
841-
using ``id``, ``name``, ``href`` and the link text.
842-
"""
843-
self.info("Clicking link '%s'." % locator)
844-
self.find_element(locator, tag='link').click()
845-
846878
@keyword
847879
def get_all_links(self):
848880
"""Returns a list containing ids of all links found in current page.
@@ -890,21 +922,6 @@ def page_should_not_contain_link(self, locator, message=None, loglevel='TRACE'):
890922
"""
891923
self.assert_page_not_contains(locator, 'link', message, loglevel)
892924

893-
@keyword
894-
def click_image(self, locator):
895-
"""Clicks an image identified by ``locator``.
896-
897-
See the `Locating elements` section for details about the locator
898-
syntax. When using the default locator strategy, images are searched
899-
using ``id``, ``name``, ``src`` and ``alt``.
900-
"""
901-
self.info("Clicking image '%s'." % locator)
902-
element = self.find_element(locator, tag='image', required=False)
903-
if not element:
904-
# A form may have an image as it's submit trigger.
905-
element = self.find_element(locator, tag='input')
906-
element.click()
907-
908925
@keyword
909926
def mouse_down_on_image(self, locator):
910927
"""Simulates a mouse down event on an image identified by ``locator``.

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,6 @@ def textarea_value_should_be(self, locator, expected, message=None):
339339
raise AssertionError(message)
340340
self.info("Content of text area '%s' is '%s'." % (locator, expected))
341341

342-
@keyword
343-
def click_button(self, locator):
344-
"""Clicks button identified by ``locator``.
345-
346-
See the `Locating elements` section for details about the locator
347-
syntax. When using the default locator strategy, buttons are
348-
searched using ``id``, ``name`` and ``value``.
349-
"""
350-
self.info("Clicking button '%s'." % locator)
351-
element = self.find_element(locator, tag='input', required=False)
352-
if not element:
353-
element = self.find_element(locator, tag='button')
354-
element.click()
355-
356342
@keyword
357343
def page_should_contain_button(self, locator, message=None, loglevel='TRACE'):
358344
"""Verifies button ``locator`` is found from current page.

0 commit comments

Comments
 (0)