Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88add0f

Browse files
authored
Merge pull request baijum#80 from educalleja/master
Added custom wait conditions
2 parents 47be3e2 + e92efac commit 88add0f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

source/waits.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ own utility package for them.
9090
The expected_conditions module contains a set of predefined conditions
9191
to use with WebDriverWait.
9292

93+
You can always create your own conditions when none of the previous convenience
94+
methods fit your requirements. You only need to create a class
95+
which __call__ method returns False when the condition isn't meet.
96+
97+
98+
::
99+
100+
class element_has_css_class(object):
101+
""" An expectation for checking that an element has a particular css class.
102+
locator - used to find the element
103+
returns the WebElement once it has the particular css class
104+
"""
105+
def __init__(self, locator, css_class):
106+
self.locator = locator
107+
self.css_class = css_class
108+
109+
def __call__(self, driver):
110+
element = driver.find_element(*self.locator) # Finding the referenced element
111+
if self.css_class in element.get_attribute("class"):
112+
return element
113+
else:
114+
return False
115+
116+
# Wait until an element with id='myNewInput' has class 'myCSSClass'
117+
wait = WebDriverWait(driver, 10)
118+
element = wait.until(element_has_css_class((By.ID, 'myNewInput'), "myCSSClass"))
119+
120+
93121

94122
Implicit Waits
95123
~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)