-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelenium
More file actions
36 lines (30 loc) · 1.11 KB
/
Copy pathSelenium
File metadata and controls
36 lines (30 loc) · 1.11 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
# Base Template
From selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Set up the Selenium webdriver
options = webdriver.ChromeOptions()
options.add_argument(--headless) # Run in headless mode (without a GUI)
driver = webdriver.Chrome(options=options)
# Set the URL to scrape
url = httpsexample.com
# Navigate to the URL
driver.get(url)
# Wait for an element to load on the page
try
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, h1))
)
# Use the element to verify that the page loaded correctly
if element.text.strip() == Welcome to Example.com
# Find all links on the page and print their text and href attributes
links = driver.find_elements(By.TAG_NAME, a)
for link in links
print(link.text.strip(), link.get_attribute(href))
else
print(Error Page did not load correctly)
except
print(Error Timed out waiting for page to load)
# Close the browser
driver.quit()