Add self.is_attribute_present(selector, attribute, value)
This commit is contained in:
parent
c6f70b78b1
commit
bcd817d57b
|
@ -776,6 +776,18 @@ class BaseCase(unittest.TestCase):
|
|||
selector, by = self.__recalculate_selector(selector, by)
|
||||
return page_actions.is_text_visible(self.driver, text, selector, by)
|
||||
|
||||
def is_attribute_present(
|
||||
self, selector, attribute, value=None, by=By.CSS_SELECTOR
|
||||
):
|
||||
"""Returns True if the element attribute/value is found.
|
||||
If the value is not specified, the attribute only needs to exist."""
|
||||
self.wait_for_ready_state_complete()
|
||||
time.sleep(0.01)
|
||||
selector, by = self.__recalculate_selector(selector, by)
|
||||
return page_actions.is_attribute_present(
|
||||
self.driver, selector, attribute, value, by
|
||||
)
|
||||
|
||||
def is_link_text_visible(self, link_text):
|
||||
self.wait_for_ready_state_complete()
|
||||
time.sleep(0.01)
|
||||
|
|
|
@ -106,6 +106,37 @@ def is_text_visible(driver, text, selector, by=By.CSS_SELECTOR):
|
|||
return False
|
||||
|
||||
|
||||
def is_attribute_present(
|
||||
driver, selector, attribute, value=None, by=By.CSS_SELECTOR
|
||||
):
|
||||
"""
|
||||
Returns whether the specified attribute is present in the given selector.
|
||||
@Params
|
||||
driver - the webdriver object (required)
|
||||
selector - the locator for identifying the page element (required)
|
||||
attribute - the attribute that is expected for the element (required)
|
||||
value - the attribute value that is expected (Default: None)
|
||||
by - the type of selector being used (Default: By.CSS_SELECTOR)
|
||||
@Returns
|
||||
Boolean (is attribute present)
|
||||
"""
|
||||
try:
|
||||
element = driver.find_element(by=by, value=selector)
|
||||
found_value = element.get_attribute(attribute)
|
||||
if found_value is None:
|
||||
raise Exception()
|
||||
|
||||
if value is not None:
|
||||
if found_value == value:
|
||||
return True
|
||||
else:
|
||||
raise Exception()
|
||||
else:
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def hover_on_element(driver, selector, by=By.CSS_SELECTOR):
|
||||
"""
|
||||
Fires the hover event for the specified element by the given selector.
|
||||
|
|
Loading…
Reference in New Issue