forked from careerist-qa/python-selenium-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
29 lines (24 loc) · 1.04 KB
/
python.py
File metadata and controls
29 lines (24 loc) · 1.04 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
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(driver_path)
driver = webdriver.Chrome(service=service)
driver.maximize_window()
# open the url
driver.get('https://www.amazon.com/')
# Locate element:
# driver.find_element() # By. / value
# Locate by ID:
driver.find_element(By.ID, 'twotabsearchtextbox')
driver.find_element(By.ID, 'nav-logo-sprites')
# By Xpath, using 1 attribute
driver.find_element(By.XPATH, "//img[@alt='Shop Studio Pro headphones']")
driver.find_element(By.XPATH, "//input[@name='field-keywords']")
driver.find_element(By.XPATH, "//input[@placeholder='Search Amazon']")
# By Xpath, multiple attributes
driver.find_element(By.XPATH, "//a[@class='nav-a ' and @href='/gp/bestsellers/?ref_=nav_cs_bestsellers' and @tabindex='0']")