-
Notifications
You must be signed in to change notification settings - Fork 44
/
RadioButtonTutorial.py
54 lines (33 loc) · 1.21 KB
/
RadioButtonTutorial.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
46
47
48
49
50
51
52
53
54
from selenium import webdriver
class RadioButton:
def __init__(self, driver, text):
self.driver = driver
self.text = text
self.button = self.driver.find_element_by_xpath("//button[contains(@class, 'btn btnLrg btnSecondary') "
"and text() = '{}']".format(text))
def is_selected(self):
return "btnSelected" in self.button.get_attribute("class")
def select(self):
self.button.click()
return self
class RadioButtonGroup:
def __init__(self, radio_buttons):
self.radio_buttons = radio_buttons
def get_selected(self):
for radio_button in self.radio_buttons:
if radio_button.is_selected():
return radio_button.text
if "__main__" == __name__:
driver = webdriver.Chrome()
driver.get("https://www.trulia.com/")
buy = RadioButton(driver, "Buy")
rent = RadioButton(driver, "Rent")
sold = RadioButton(driver, "Sold")
group = RadioButtonGroup([buy, rent, sold])
print group.get_selected()
buy.select()
print group.get_selected()
rent.select()
print group.get_selected()
sold.select()
print group.get_selected()