Created
May 7, 2022 22:16
-
-
Save glciampaglia/b51b7264afb01e61078a584b7b7f114f to your computer and use it in GitHub Desktop.
Selenium test (Chrome webdriver)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support.expected_conditions import \ | |
presence_of_element_located | |
# This example requires Selenium WebDriver 3.13 or newer | |
with webdriver.Chrome() as driver: | |
wait = WebDriverWait(driver, 10) | |
driver.get("https://google.com/ncr") | |
driver.find_element(By.NAME, "q").send_keys("cheese") | |
time.sleep(1) | |
driver.find_element(By.NAME, "q").send_keys(Keys.RETURN) | |
first_result = wait.until(presence_of_element_located( | |
(By.CSS_SELECTOR, "h3>div"))) | |
for i in range(11): | |
time.sleep(1) | |
print(10 - i) | |
print(first_result.get_attribute("textContent")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment