Add self.get_attribute() to simplify things a bit

This commit is contained in:
Michael Mintz 2016-05-16 19:48:29 -04:00
parent be8b69feaa
commit 6f077f3666
1 changed files with 11 additions and 0 deletions

View File

@ -89,6 +89,17 @@ class BaseCase(unittest.TestCase):
self.driver, selector, by, timeout)
return element.text
def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
element = page_actions.wait_for_element_present(
self.driver, selector, by, timeout)
attribute_value = element.get_attribute(attribute)
if attribute_value is not None:
return attribute_value
else:
raise Exception("Element [%s] has no attribute [%s]!" % (
selector, attribute))
def add_text(self, selector, new_value, timeout=settings.SMALL_TIMEOUT):
""" The more-reliable version of driver.send_keys()
Similar to update_text(), but won't clear the text field first. """