Skip to content

Commit eeb5024

Browse files
pekkaklarckaaltat
authored andcommitted
Make checkbox keywords not to work with radio buttons (robotframework#964)
* Better error if element with certain type not found. Also changed type names to more human readable format. Make checkbox keywords not to work with radio buttons Fixes robotframework#962.
1 parent 4e48199 commit eeb5024

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

src/SeleniumLibrary/keywords/element.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,15 @@ def click_link(self, locator):
593593
link text.
594594
"""
595595
self.info("Clicking link '%s'." % locator)
596-
self.find_element(locator, tag='a').click()
596+
self.find_element(locator, tag='link').click()
597597

598598
@keyword
599599
def get_all_links(self):
600600
"""Returns a list containing ids of all links found in current page.
601601
602602
If a link has no id, an empty string will be in the list instead.
603603
"""
604-
links = self.find_elements("tag=a", tag='a')
604+
links = self.find_elements("tag=a")
605605
return [link.get_attribute('id') for link in links]
606606

607607
@keyword
@@ -612,7 +612,7 @@ def mouse_down_on_link(self, locator):
612612
syntax. Key attributes for links are ``id``, ``name``, ``href`` and
613613
link text.
614614
"""
615-
element = self.find_element(locator, tag='a')
615+
element = self.find_element(locator, tag='link')
616616
action = ActionChains(self.browser)
617617
action.click_and_hold(element).perform()
618618

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def _get_value(self, locator, tag):
367367
return self.find_element(locator, tag).get_attribute('value')
368368

369369
def _get_checkbox(self, locator):
370-
return self.find_element(locator, tag='input')
370+
return self.find_element(locator, tag='checkbox')
371371

372372
def _get_radio_buttons(self, group_name):
373373
xpath = "xpath://input[@type='radio' and @name='%s']" % group_name

src/SeleniumLibrary/keywords/selectelement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def _get_labels_for_options(self, options):
395395
return labels
396396

397397
def _get_select_list(self, locator):
398-
el = self.find_element(locator, tag='select')
398+
el = self.find_element(locator, tag='list')
399399
return Select(el)
400400

401401
def _get_select_list_options(self, select_list_or_locator):

src/SeleniumLibrary/locators/elementfinder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, ctx):
6060

6161
def find(self, locator, tag=None, first_only=True, required=True,
6262
parent=None):
63+
element_type = 'Element' if not tag else tag.capitalize()
6364
if parent and not self._is_webelement(parent):
6465
raise ValueError('Parent must be Selenium WebElement but it '
6566
'was {}'.format(type(parent)))
@@ -71,8 +72,8 @@ def find(self, locator, tag=None, first_only=True, required=True,
7172
elements = strategy(criteria, tag, constraints,
7273
parent=parent or self.browser)
7374
if required and not elements:
74-
raise ElementNotFound("Element with locator '{}' not found."
75-
.format(locator))
75+
raise ElementNotFound("{} with locator '{}' not found."
76+
.format(element_type, locator))
7677
if first_only:
7778
if not elements:
7879
return None

test/acceptance/keywords/checkbox_and_radio_buttons.robot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ UnSelect Checkbox
3232
Unselect Checkbox can_send_email
3333
Checkbox Should Not Be Selected can_send_email
3434

35+
Checkbox keywords don't work with radio buttons
36+
Run Keyword And Expect Error
37+
... Page should have contained checkbox 'referrer' but did not.
38+
... Page Should Contain Checkbox referrer
39+
Page Should Not Contain Checkbox referrer
40+
Run Keyword And Expect Error
41+
... Checkbox with locator 'referrer' not found.
42+
... Checkbox Should Be Selected referrer
43+
Run Keyword And Expect Error
44+
... Checkbox with locator 'referrer' not found.
45+
... Checkbox Should Not Be Selected referrer
46+
Run Keyword And Expect Error
47+
... Checkbox with locator 'referrer' not found.
48+
... Select Checkbox referrer
49+
Run Keyword And Expect Error
50+
... Checkbox with locator 'referrer' not found.
51+
... Unselect Checkbox referrer
52+
3553
Radio Button Should Be Set To
3654
[Documentation] LOG 2 Verifying radio button 'sex' has selection 'female'.
3755
Radio Button Should Be Set To sex female
@@ -65,3 +83,11 @@ Radio button not found
6583
Run Keyword And Expect Error
6684
... No radio button with name 'nonex' found.
6785
... Radio button should be set to nonex whatever
86+
87+
Radio button keywords don't work with checkboxes
88+
Run Keyword And Expect Error
89+
... No radio button with name 'can_send_email' and value 'whatever' found.
90+
... Select Radio Button can_send_email whatever
91+
Run Keyword And Expect Error
92+
... No radio button with name 'can_send_email' found.
93+
... Radio button should be set to can_send_email whatever

0 commit comments

Comments
 (0)