Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created June 7, 2024 05:37
Show Gist options
  • Save SarahElson/52bc03647938a6f9a93df0ba9131c90d to your computer and use it in GitHub Desktop.
Save SarahElson/52bc03647938a6f9a93df0ba9131c90d to your computer and use it in GitHub Desktop.
How to Wait in Python: Python Wait Tutorial With Examples
import pytest
from pages.explicit_wait import *
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
@pytest.mark.usefixtures("driver")
def test_explicit_wait_email_input(driver):
explicit_wait = ExplicitWait(driver)
explicit_wait.click_my_account()
# explicit wait method
email_input = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "email"))
)
email = "[email protected]"
email_input.send_keys(email)
assert email_input.get_property("value") == email, f"Expected email value to equal {email}"
@pytest.mark.usefixtures("driver")
def test_explicit_wait_for_button(driver):
explicit_wait = ExplicitWait(driver)
explicit_wait.click_my_account()
# explicit wait
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@type='submit']"))
)
button = explicit_wait.get_submit_button()
button_text = button.get_attribute('value')
assert button_text == "Login", f"Expected {button_text} to be Login"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment