-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuiControls.py
More file actions
58 lines (42 loc) · 2.12 KB
/
uiControls.py
File metadata and controls
58 lines (42 loc) · 2.12 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
service_obj = Service("C:/Users/Martin/Documents/chromedriver.exe")
# chrome driver... manually configured way...by providing the path to the downloaded driver...
driver = webdriver.Chrome(service=service_obj)
driver.get("https://rahulshettyacademy.com/AutomationPractice/")
checkboxes = driver.find_elements(By.XPATH, "(//input[@type='checkbox'])") # returns a list of said element...
print(f"There are {len(checkboxes)} returned... ")
for checkbox in checkboxes:
if checkbox.get_attribute("value") == "option2":
print(f"option returned is: {checkbox.get_attribute('value')}")
checkbox.click()
assert checkbox.is_selected() # boolean function...
break
radioButtons = driver.find_elements(By.CSS_SELECTOR, ".radioButton") # returns a list of said element...
# radioButtons[2].click()
print(f"There are {len(radioButtons)} radio buttons returned... ")
for radioButton in radioButtons:
if radioButton.get_attribute("value") == "radio3":
print(f"radioBut returned is: {radioButton.get_attribute('value')}")
radioButton.click()
assert radioButton.is_selected() # if not selected, assertion will fail...
break
# create XPATH for radio button (trying to get radio2)
# (//input[@type='radio'])[2] # selects radio button 3... indexes 0, 1, 2
# using the class attribute:
# .radioButton:nth-child(2) # selects radio button 2...
# create XPATH locator:
# if id, value, or name attributes weren't available then do this:
# (//input[@type='checkbox'])[2] # selects option 2 checkbox...
# (//input[@type='checkbox']) # this returns 3 checkboxes...
# is displayed...
assert driver.find_element(By.ID, "displayed-text").is_displayed()
driver.find_element(By.ID, "hide-textbox").click() # clicks on hide button thus hiding the field
assert not driver.find_element(By.ID, "displayed-text").is_displayed() # using negation...
'''
NEXT LECTURE: Handling Java / JavaScript Alert popups using Selenium...
9:00 min
lecture number: lectures/13248307
'''