Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1496 from psav/buttongroup
Browse files Browse the repository at this point in the history
Adding a ButtonGroup widget
  • Loading branch information
Milan Falešník committed Jan 8, 2015
2 parents 153b44b + dea2491 commit 88a1498
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cfme/web_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,3 +2766,52 @@ def expand_all_sections(self):
)
for el in els_to_expand:
el.click()


class ButtonGroup(object):
def __init__(self, key):
""" A ButtonGroup is a set of buttons next to each other, as is used on the DefaultViews
page.
Args:
key: The name of the key field text before the button group.
"""
self.key = key
self.locator = '//td[@class="key" and text()="{}"]/..'.format(self.key)

def locate(self):
""" Moves to the element """
# Use the header locator as the overall table locator
return sel.move_to_element(self.locator)

@property
def active(self):
""" Returns the alt tag text of the active button in thr group. """
loc = sel.element(self.locator + '/td[2]/ul/li[@class="active"]/img')
return loc.get_attribute('alt')

def status(self, alt):
""" Returns the status of the button identified by the Alt Text of the image. """
active_loc = self.locator + '/td[2]/ul/li/img[@alt="{}"]'.format(alt)
try:
sel.element(active_loc)
return True
except NoSuchElementException:
pass
inactive_loc = self.locator + '/td[2]/ul/li/a/img[@alt="{}"]'.format(alt)
try:
sel.element(inactive_loc)
return False
except NoSuchElementException:
pass

def choose(self, alt):
""" Sets the ButtonGroup to select the button identified by the alt text. """
if not self.status(alt):
inactive_loc = self.locator + '/td[2]/ul/li/a/img[@alt="{}"]'.format(alt)
sel.click(inactive_loc)


@fill.method((ButtonGroup, basestring))
def _fill_showing_button_group(tb, s):
tb.choose(s)

0 comments on commit 88a1498

Please sign in to comment.