Book Image

Learning Selenium Testing Tools with Python

By : UNMESH GUNDECHA
Book Image

Learning Selenium Testing Tools with Python

By: UNMESH GUNDECHA

Overview of this book

Table of Contents (17 chapters)
Learning Selenium Testing Tools with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing custom wait conditions


As we have seen earlier, the expected_conditions class provides various predefined conditions to wait. We can also build custom conditions with WebDriverWait. This becomes useful when there is no suitable expected condition available for which to wait.

Let's modify one of the tests we created earlier in this chapter and implement a custom wait condition to check the number of the drop-down items:

def testLoginLink(self):
    WebDriverWait(self.driver, 10).until(lambda s: s.find_element_by_id "select-language").get_attribute("length") == "3")

    login_link = WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located((By.LINK_TEXT,"Log In")))
       login_link.click();

We can implement custom wait conditions with WebDriverWait using the Python lambda expressions. In this example, the script will wait for 10 seconds until the Select Language dropdown has eight options for selection. This condition is useful when the dropdowns are...