Skip to content

Commit a65ff1c

Browse files
Add attribute_to_be_include method to expected_conditions when the at… (#9200)
* Add attribute_to_be_include method to expected_conditions when the attribute given is include the element's attributes Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 3d8f879 commit a65ff1c

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

py/selenium/webdriver/support/expected_conditions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ def _predicate(driver):
364364
return _predicate
365365

366366

367+
def element_attribute_to_include(locator, attribute_):
368+
""" An expectation for checking if the given attribute is include in the
369+
specified element.
370+
locator, attribute
371+
"""
372+
def _predicate(driver):
373+
try:
374+
element_attribute = driver.find_element(*locator).get_attribute(attribute_)
375+
return element_attribute is not None
376+
except StaleElementReferenceException:
377+
return False
378+
379+
return _predicate
380+
381+
367382
def any_of(*expected_conditions):
368383
""" An expectation that any of multiple expected conditions is true.
369384
Equivalent to a logical 'OR'.

py/test/selenium/webdriver/common/webdriverwait_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,11 @@ def testExpectedConditionAlertIsPresent(driver, pages):
315315
alert = driver.switch_to.alert
316316
assert 'alerty' == alert.text
317317
alert.dismiss()
318+
319+
320+
def testExpectedConditionAttributeToBeIncludeInElement(driver, pages):
321+
pages.load('booleanAttributes.html')
322+
with pytest.raises(TimeoutException):
323+
WebDriverWait(driver, 1).until(EC.element_attribute_to_include((By.ID, 'inputRequired'), 'test'))
324+
value = WebDriverWait(driver, 1).until(EC.element_attribute_to_include((By.ID, 'inputRequired'), 'value'))
325+
assert value is not None

0 commit comments

Comments
 (0)