-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdown1.py
More file actions
49 lines (35 loc) · 1.17 KB
/
Copy pathdropdown1.py
File metadata and controls
49 lines (35 loc) · 1.17 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
driver.maximize_window()
login_url = "https://the-internet.herokuapp.com/dropdown"
driver.get(login_url)
dropdown_element = driver.find_element(By.ID, value="dropdown")
# Select = Select(dropdown_element)
# Select the value by visible text
# Select the value by Index
# Select the option by using a value
# Select.select_by_visible_text("Option 2")
# Select.select_by_index(2)
# Select.select_by_value("2")
# option_count = len(Select.options)
# expected_count = 3
# if option_count == expected_count:
# print("Test case passed. Count is correct")
# else:
# print("Test case failed. Count is incorrect")
# while True:
# pass
target_value = "Option 2"
select = Select(dropdown_element)
for option in select.options:
if option.text == target_value:
option.click()
print(f"Selected Option is {target_value}")
break
else:
print(f"Option '{target_value}' not found")
while True:
pass