https://github.com/lana-20/waiting-strategies
Waiting Strategies - Appium and Selenium Automation
https://github.com/lana-20/waiting-strategies
Last synced: 4 months ago
JSON representation
Waiting Strategies - Appium and Selenium Automation
- Host: GitHub
- URL: https://github.com/lana-20/waiting-strategies
- Owner: lana-20
- Created: 2023-12-02T21:57:49.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-11T12:32:46.000Z (almost 2 years ago)
- Last Synced: 2025-06-07T20:05:44.181Z (4 months ago)
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Waiting Strategies - Appium and Selenium Automation
The repo contains code snippets used in this [post](..medium post..).### NoSuchElementException
from selenium.common.exceptions import NoSuchElementException
...
def test_demo():
driver = webdriver.Remote(server_url, caps)
try:
element = driver.find_element(By.ID, "foo")
element.click()
except NoSuchElementException:
print(driver.page_source)
raise
finally:
driver.quit()### Static Wait

def test_login_static_wait():
time.sleep(3)
driver.find_element(login_screen).click()
time.sleep(3)
driver.find_element(username).send_keys(AUTH_USER)
driver.find_element(password).send_keys(AUTH_PASS)
driver.find_element(login_button).click()
time.sleep(3)
driver.find_element(get_logged_in_by(AUTH_USER))### Implicit Wait
def test_login_implicit_wait():
driver.implicitly_wait(10)
driver.find_element(login_screen).click()
driver.find_element(username).send_keys(AUTH_USER)
driver.find_element(password).send_keys(AUTH_PASS)
driver.find_element(login_button).click()
driver.find_element(get_logged_in_by(AUTH_USER))### Explicit Wait

def test_login_explicit_wait():
wait = WebDriverWait(driver, 10)
wait.until(expected_conditions.presence_of_element_located(login_screen)).click()
wait.until(expected_conditions.presence_of_element_located(username)).send_keys(AUTH_USER)
wait.until(expected_conditions.presence_of_element_located(password)).send_keys(AUTH_PASS)
wait.until(expected_conditions.presence_of_element_located(login_button)).click()
wait.until(expected_conditions.presence_of_element_located(get_logged_in_by(AUTH_USER)))
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "foo"))
)### Custom Explicit Wait

class tap_is_successful(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
try:
element = driver.find_element(*self.locator)
element.click()
return True
except:
return False
wait = WebDriverWait(driver, 10)
wait.until(tap_is_successful(By.ID, "foo"))
class element_found_and_clicked(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
try:
element = driver.find_element(*self.locator)
element.click()
return True
except:
return False
def test_login_custom_wait():
wait = WebDriverWait(driver, 10)
wait.until(element_found_and_clicked(login_screen))
wait.until(expected_conditions.presence_of_element_located(username)).send_keys(AUTH_USER)
wait.until(expected_conditions.presence_of_element_located(password)).send_keys(AUTH_PASS)
wait.until(element_found_and_clicked(login_button))
wait.until(expected_conditions.presence_of_element_located(get_logged_in_by(AUTH_USER)))### Fluent Wait

wait = WebDriverWait(
driver, timeout=10, poll_frequency=2, ignored_exceptions=ignore_list
)