Skip to content

Commit

Permalink
Merge pull request #80 from educalleja/master
Browse files Browse the repository at this point in the history
Added custom wait conditions
  • Loading branch information
baijum committed Aug 14, 2017
2 parents 47be3e2 + e92efac commit 88add0f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/waits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ own utility package for them.
The expected_conditions module contains a set of predefined conditions
to use with WebDriverWait.

You can always create your own conditions when none of the previous convenience
methods fit your requirements. You only need to create a class
which __call__ method returns False when the condition isn't meet.


::

class element_has_css_class(object):
""" An expectation for checking that an element has a particular css class.
locator - used to find the element
returns the WebElement once it has the particular css class
"""
def __init__(self, locator, css_class):
self.locator = locator
self.css_class = css_class

def __call__(self, driver):
element = driver.find_element(*self.locator) # Finding the referenced element
if self.css_class in element.get_attribute("class"):
return element
else:
return False
# Wait until an element with id='myNewInput' has class 'myCSSClass'
wait = WebDriverWait(driver, 10)
element = wait.until(element_has_css_class((By.ID, 'myNewInput'), "myCSSClass"))



Implicit Waits
~~~~~~~~~~~~~~
Expand Down

0 comments on commit 88add0f

Please sign in to comment.