15c36fc454fa6ce9e360ffde4e807038c400332f
[WebKit-https.git] / WebDriverTests / imported / w3c / webdriver / tests / element_click / select.py
1 from tests.support.inline import inline
2
3
4 def test_click_option(session):
5     session.url = inline("""
6       <select>
7         <option>first
8         <option>second
9       </select>""")
10     options = session.find.css("option")
11
12     assert options[0].selected
13     assert not options[1].selected
14
15     options[1].click()
16     assert options[1].selected
17     assert not options[0].selected
18
19
20 def test_click_multiple_option(session):
21     session.url = inline("""
22       <select multiple>
23         <option>first
24         <option>second
25       </select>""")
26     options = session.find.css("option")
27
28     assert not options[0].selected
29     assert not options[1].selected
30
31     options[0].click()
32     assert options[0].selected
33     assert not options[1].selected
34
35
36 def test_click_preselected_option(session):
37     session.url = inline("""
38       <select>
39         <option>first
40         <option selected>second
41       </select>""")
42     options = session.find.css("option")
43
44     assert not options[0].selected
45     assert options[1].selected
46
47     options[1].click()
48     assert options[1].selected
49     assert not options[0].selected
50
51     options[0].click()
52     assert options[0].selected
53     assert not options[1].selected
54
55
56 def test_click_preselected_multiple_option(session):
57     session.url = inline("""
58       <select multiple>
59         <option>first
60         <option selected>second
61       </select>""")
62     options = session.find.css("option")
63
64     assert not options[0].selected
65     assert options[1].selected
66
67     options[1].click()
68     assert not options[1].selected
69     assert not options[0].selected
70
71     options[0].click()
72     assert options[0].selected
73     assert not options[1].selected
74
75
76 def test_click_deselects_others(session):
77     session.url = inline("""
78       <select>
79         <option>first
80         <option>second
81         <option>third
82       </select>""")
83     options = session.find.css("option")
84
85     options[0].click()
86     assert options[0].selected
87     options[1].click()
88     assert options[1].selected
89     options[2].click()
90     assert options[2].selected
91     options[0].click()
92     assert options[0].selected
93
94
95 def test_click_multiple_does_not_deselect_others(session):
96     session.url = inline("""
97       <select multiple>
98         <option>first
99         <option>second
100         <option>third
101       </select>""")
102     options = session.find.css("option")
103
104     options[0].click()
105     assert options[0].selected
106     options[1].click()
107     assert options[0].selected
108     assert options[1].selected
109     options[2].click()
110     assert options[0].selected
111     assert options[1].selected
112     assert options[2].selected
113
114
115 def test_click_selected_option(session):
116     session.url = inline("""
117       <select>
118         <option>first
119         <option>second
120       </select>""")
121     options = session.find.css("option")
122
123     # First <option> is selected in dropdown
124     assert options[0].selected
125     assert not options[1].selected
126
127     options[1].click()
128     assert options[1].selected
129     options[1].click()
130     assert options[1].selected
131
132
133 def test_click_selected_multiple_option(session):
134     session.url = inline("""
135       <select multiple>
136         <option>first
137         <option>second
138       </select>""")
139     options = session.find.css("option")
140
141     # No implicitly selected <option> in <select multiple>
142     assert not options[0].selected
143     assert not options[1].selected
144
145     options[0].click()
146     assert options[0].selected
147     assert not options[1].selected
148
149     # Second click in <select multiple> deselects
150     options[0].click()
151     assert not options[0].selected
152     assert not options[1].selected
153
154
155 def test_out_of_view_dropdown(session):
156     session.url = inline("""
157       <select>
158         <option>1
159         <option>2
160         <option>3
161         <option>4
162         <option>5
163         <option>6
164         <option>7
165         <option>8
166         <option>9
167         <option>10
168         <option>11
169         <option>12
170         <option>13
171         <option>14
172         <option>15
173         <option>16
174         <option>17
175         <option>18
176         <option>19
177         <option>20
178       </select>""")
179     options = session.find.css("option")
180
181     options[14].click()
182     assert options[14].selected
183
184
185 def test_out_of_view_multiple(session):
186     session.url = inline("""
187       <select multiple>
188         <option>1
189         <option>2
190         <option>3
191         <option>4
192         <option>5
193         <option>6
194         <option>7
195         <option>8
196         <option>9
197         <option>10
198         <option>11
199         <option>12
200         <option>13
201         <option>14
202         <option>15
203         <option>16
204         <option>17
205         <option>18
206         <option>19
207         <option>20
208       </select>""")
209     options = session.find.css("option")
210
211     last_option = options[-1]
212     last_option.click()
213     assert last_option.selected