forked from careerist-qa/python-selenium-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocators.py
More file actions
42 lines (28 loc) · 1.38 KB
/
Locators.py
File metadata and controls
42 lines (28 loc) · 1.38 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
41
42
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
# create a new Chrome browser instance
service = Service(executable_path='<provide your absolute path>')
driver = webdriver.Chrome(service=service)
# By ID
driver.find_element(By.ID, 'nav-search-submit-button')
driver.find_element(By.ID, 'nav-cart-count')
# By XPATH
# Tag and attribute
driver.find_element(By.XPATH, "//a[@data-csa-c-content-id='nav_cs_bestsellers']")
driver.find_element(By.XPATH, "//input[@aria-label='Search Amazon']")
# Multiple attributes
driver.find_element(By.XPATH, "//a[@class='nav-a ' and @data-csa-c-content-id='nav_cs_bestsellers']")
# By Xpath, text
driver.find_element(By.XPATH, "//a[text()='Best Sellers']")
driver.find_element(By.XPATH, "//a[text()='Best Sellers' and @class='nav-a ']")
# Any tag = *
driver.find_element(By.XPATH, "//*[text()='Best Sellers' and @class='nav-a ']")
# Contains
driver.find_element(By.XPATH, "//a[contains(@href, 'nav_cs_bestsellers')]")
driver.find_element(By.XPATH, "//a[contains(text(), 't Seller') and @class='nav-a ']")
# //parent[...]//child[...]
driver.find_element(By.XPATH, "//div[@id='nav-belt']//input[@placeholder='Search Amazon']")
# Allure Terminal Commands
# behave -f allure_behave.formatter:AllureFormatter -o test_results/ features/tests/amazon_search.feature
# allure serve test_results/