...
Code Block | ||
---|---|---|
| ||
element_id = object def find_the_element_by_id(driver, element_id): element = driver.find_element_by_id(element_id) if element: return element else: return False def function_where_test_written(): global element_id element_id = "qa" qa = WebDriverWait(driver, 1).until(find_the_element_by_id) qa.click() |
...
Line 3-8 : create a function that does the query on the DOM using the webdriver that is passed in
Line 11 13 : specify the thing that you want search for
Line 12 14 : use a special API call WebDriverWait() that tells the webdriver (the first parameter being passed in) to wait for a certain period (the second parameter, in this example up to 1 second) until calling your query function “find_the_element_by_id” - this is passed into the until() method. Essentially it causes the WebDriver to slow down until the DOM is stable (in other words the page has been properly loaded).
Line 13 15 : perform your action on the element as normal
...