File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,34 @@ own utility package for them.
90
90
The expected_conditions module contains a set of predefined conditions
91
91
to use with WebDriverWait.
92
92
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
+
93
121
94
122
Implicit Waits
95
123
~~~~~~~~~~~~~~
You can’t perform that action at this time.
0 commit comments