This repository was archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path3-elements.py
48 lines (34 loc) · 1.58 KB
/
3-elements.py
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
43
44
45
from selenium import webdriver
import time
# Create the webdriver instance
# run test locally against chrome
driver = webdriver.Chrome("./webdrivers/chromedriver")
# run test in CrossBrowserTesting:
# driver = webdriver.Remote(
# command_executor = "https://hub.crossbrowsertesting.com/wd/hub",
# desired_capabilities = { "browser": "chrome",
# "version": "latest",
# "platform": "windows",
# # "deviceName": "Pixel 3",
# "username": "[email protected]",
# "password": "u0af4e32dc4fb29d",
# "recordVideo": True})
# navigate
driver.get("http://crossbrowsertesting.github.io/login-form.html")
# find the search box
# ...using xpath
username = driver.find_element_by_xpath('/html/body/div/div/div/div/form/div[1]/input')
password = driver.find_element_by_xpath('/html/body/div/div/div/div/form/div[2]/input')
login = driver.find_element_by_xpath('/html/body/div/div/div/div/form/div[3]/button')
# ...using css selectors
(username, password) = driver.find_elements_by_css_selector('[name="login-form"] input')
login = driver.find_element_by_css_selector('[name="login-form"] button')
# ...or using ids
username = driver.find_element_by_id('username')
password = driver.find_element_by_id('password')
login = driver.find_element_by_id('submit')
username.send_keys('[email protected]')
password.send_keys('test123')
login.click()
raw_input('press enter to quit')
driver.quit()