-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_script.py
More file actions
40 lines (32 loc) · 1.35 KB
/
sample_script.py
File metadata and controls
40 lines (32 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
# get the path to the ChromeDriver executable
# driver_path = ChromeDriverManager().install()
# create a new Chrome browser instance
service = Service(executable_path=r'C:\Users\white\my-python-selenium-automation\chromedriver.exe')
driver = webdriver.Chrome(service=service)
driver.maximize_window()
driver.implicitly_wait(5)
driver.wait = WebDriverWait(driver, 10)
search_btn = (By.NAME, 'btnK')
# open the url
driver.get('https://www.google.com/')
# populate search field
search = driver.find_element(By.NAME, 'q')
search.clear()
search.send_keys('car')
# Has to be defined in code where the wait is used
# it waits for the condition to be met every 500 ms
# always fails with timeout exception
# supports custom conditions, usually taken from EC
# click search button
driver.wait.until(EC.element_to_be_clickable(search_btn), message='Search btn not clickable').click()
# verify search results
assert 'car'.lower() in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}"
print('Test Passed')
driver.quit()