Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected condition for checking attribute value #9881

Merged
merged 3 commits into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions py/selenium/webdriver/support/expected_conditions.py
Expand Up @@ -218,7 +218,7 @@ def _predicate(driver):

def text_to_be_present_in_element_value(locator, text_):
"""
An expectation for checking if the given text is present in the element's
An expectation for checking if the given text is present in the element's value.
locator, text
"""

Expand All @@ -234,6 +234,26 @@ def _predicate(driver):
return _predicate


def text_to_be_present_in_element_attribute(locator, attribute_, text_):
"""
An expectation for checking if the given text is present in the element's attribute.
locator, attribute, text
"""

def _predicate(driver):
try:
if not element_attribute_to_include(locator, attribute_):
return False
element_text = driver.find_element(*locator).get_attribute(attribute_)
return text_ in element_text
except InvalidSelectorException as e:
raise e
except StaleElementReferenceException:
return False

return _predicate


def frame_to_be_available_and_switch_to_it(locator):
""" An expectation for checking whether the given frame is available to
switch to. If the frame is available it switches the given driver to the
Expand Down Expand Up @@ -414,7 +434,7 @@ def _predicate(driver):


def element_attribute_to_include(locator, attribute_):
""" An expectation for checking if the given attribute is include in the
""" An expectation for checking if the given attribute is included in the
specified element.
locator, attribute
"""
Expand Down
9 changes: 9 additions & 0 deletions py/test/selenium/webdriver/common/webdriverwait_tests.py
Expand Up @@ -212,6 +212,15 @@ def testExpectedConditionTextToBePresentInElementValue(driver, pages):
assert 'Example Expected text' == driver.find_element(By.ID, 'inputRequired').get_attribute('value')


def testExpectedConditionTextToBePresentInElementAttribute(driver, pages):
pages.load('booleanAttributes.html')
with pytest.raises(TimeoutException):
WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_attribute((By.ID, 'inputRequired'), 'value', 'Expected'))
driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)")
WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_attribute((By.ID, 'inputRequired'), 'value', 'Expected'))
assert 'Example Expected text' == driver.find_element(By.ID, 'inputRequired').get_attribute('value')


# xfail can be removed after 23 March 2021
@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1691348")
def testExpectedConditionFrameToBeAvailableAndSwitchToItByLocator(driver, pages):
Expand Down