View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.html;
16  
17  import java.util.List;
18  
19  import org.htmlunit.HttpMethod;
20  import org.htmlunit.WebDriverTestCase;
21  import org.htmlunit.junit.annotation.Alerts;
22  import org.htmlunit.junit.annotation.BuggyWebDriver;
23  import org.junit.jupiter.api.Test;
24  import org.openqa.selenium.By;
25  import org.openqa.selenium.WebDriver;
26  import org.openqa.selenium.WebElement;
27  import org.openqa.selenium.interactions.Actions;
28  
29  /**
30   * Tests for {@link HTMLSelectElement}.
31   *
32   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
33   * @author David K. Taylor
34   * @author Marc Guillemot
35   * @author Bruce Faulkner
36   * @author Ahmed Ashour
37   * @author Daniel Gredler
38   * @author Ronald Brill
39   * @author Frank Danek
40   * @author Carsten Steul
41   */
42  public class HTMLSelectElementTest extends WebDriverTestCase {
43  
44      /**
45       * @throws Exception if the test fails
46       */
47      @Test
48      @Alerts({"3", "1", "3", "0"})
49      public void getSelectedIndex() throws Exception {
50          final String html = DOCTYPE_HTML
51              + "<html>\n"
52              + "<head>\n"
53              + "  <script>\n"
54              + LOG_TITLE_FUNCTION
55              + "    function doTest() {\n"
56              + "      log(document.form1.select1.length);\n"
57              + "      log(document.form1.select1.selectedIndex);\n"
58  
59              + "      log(document.form1.selectMulti.length);\n"
60              + "      log(document.form1.selectMulti.selectedIndex);\n"
61              + "    }\n"
62              + "  </script>\n"
63              + "</head>\n"
64              + "<body onload='doTest()'>\n"
65              + "  <form name='form1'>\n"
66              + "    <select name='select1'>\n"
67              + "      <option name='option1'>One</option>\n"
68              + "      <option name='option2' selected>Two</option>\n"
69              + "      <option name='option3'>Three</option>\n"
70              + "    </select>\n"
71  
72              + "    <select name='selectMulti' multiple>\n"
73              + "      <option name='option1' selected>One</option>\n"
74              + "      <option name='option2'>Two</option>\n"
75              + "      <option name='option3' selected>Three</option>\n"
76              + "    </select>\n"
77              + "  </form>\n"
78              + "</body></html>";
79  
80          loadPageVerifyTitle2(html);
81      }
82  
83      /**
84       * @throws Exception if the test fails
85       */
86      @Test
87      @Alerts({"3", "0", "3", "-1"})
88      public void getSelectedIndexNothingSelected() throws Exception {
89          final String html = DOCTYPE_HTML
90              + "<html>\n"
91              + "<head>\n"
92              + "  <script>\n"
93              + LOG_TITLE_FUNCTION
94              + "    function doTest() {\n"
95              + "      log(document.form1.select1.length);\n"
96              + "      log(document.form1.select1.selectedIndex);\n"
97  
98              + "      log(document.form1.selectMulti.length);\n"
99              + "      log(document.form1.selectMulti.selectedIndex);\n"
100             + "    }\n"
101             + "  </script>\n"
102             + "</head>\n"
103             + "<body onload='doTest()'>\n"
104             + "  <form name='form1'>\n"
105             + "    <select name='select1'>\n"
106             + "      <option name='option1'>One</option>\n"
107             + "      <option name='option2'>Two</option>\n"
108             + "      <option name='option3'>Three</option>\n"
109             + "    </select>\n"
110 
111             + "    <select name='selectMulti' multiple>\n"
112             + "      <option name='option1'>One</option>\n"
113             + "      <option name='option2'>Two</option>\n"
114             + "      <option name='option3'>Three</option>\n"
115             + "    </select>\n"
116             + "  </form>\n"
117             + "</body></html>";
118 
119         loadPageVerifyTitle2(html);
120     }
121 
122     /**
123      * @throws Exception if the test fails
124      */
125     @Test
126     @Alerts({"0", "-1", "0", "-1"})
127     public void getSelectedIndexNoOption() throws Exception {
128         final String html = DOCTYPE_HTML
129             + "<html>\n"
130             + "<head>\n"
131             + "  <script>\n"
132             + LOG_TITLE_FUNCTION
133             + "    function doTest() {\n"
134             + "      log(document.form1.select1.length);\n"
135             + "      log(document.form1.select1.selectedIndex);\n"
136 
137             + "      log(document.form1.selectMulti.length);\n"
138             + "      log(document.form1.selectMulti.selectedIndex);\n"
139             + "    }\n"
140             + "  </script>\n"
141             + "</head>\n"
142             + "<body onload='doTest()'>\n"
143             + "  <form name='form1'>\n"
144             + "    <select name='select1'>\n"
145             + "    </select>\n"
146             + "    <select name='selectMulti' multiple>\n"
147             + "    </select>\n"
148             + "  </form>\n"
149             + "</body></html>";
150 
151         loadPageVerifyTitle2(html);
152     }
153 
154     /**
155      * @throws Exception if the test fails
156      */
157     @Test
158     @Alerts({"3", "1", "3", "2"})
159     public void setSelectedIndex() throws Exception {
160         final String html = DOCTYPE_HTML
161             + "<html>\n"
162             + "<head>\n"
163             + "  <script>\n"
164             + LOG_TITLE_FUNCTION
165             + "    function doTest() {\n"
166             + "      log(document.form1.select1.length);\n"
167             + "      log(document.form1.select1.selectedIndex);\n"
168 
169             + "      document.form1.select1.selectedIndex = 2;\n"
170             + "      log(document.form1.select1.length);\n"
171             + "      log(document.form1.select1.selectedIndex);\n"
172             + "      document.form1.select1.selectedIndex = -1;\n"
173             + "    }\n"
174             + "  </script>\n"
175             + "</head>\n"
176             + "<body onload='doTest()'>\n"
177             + "  <form name='form1' action='/foo' method='get'>\n"
178             + "    <select name='select1'>\n"
179             + "      <option value='option1' name='option1'>One</option>\n"
180             + "      <option value='option2' name='option2' selected>Two</option>\n"
181             + "      <option value='option3' name='option3'>Three</option>\n"
182             + "    </select>\n"
183             + "    <input type='submit' id='clickMe' name='submit' value='button'>\n"
184             + "</form>\n"
185             + "</body></html>";
186 
187         getMockWebConnection().setDefaultResponse("");
188 
189         final WebDriver webdriver = loadPageVerifyTitle2(html);
190         webdriver.findElement(By.id("clickMe")).click();
191 
192         assertEquals(URL_FIRST + "foo?submit=button", webdriver.getCurrentUrl());
193         assertSame("method", HttpMethod.GET, getMockWebConnection().getLastMethod());
194     }
195 
196     /**
197      * @throws Exception if the test fails
198      */
199     @Test
200     @Alerts("0")
201     public void selectedIndex2() throws Exception {
202         final String html = DOCTYPE_HTML
203             + "<html>\n"
204             + "<head>\n"
205             + "  <script>\n"
206             + LOG_TITLE_FUNCTION
207             + "    function doTest() {\n"
208             + "      var oSelect = document.getElementById('main');\n"
209             + "      var oOption = new Option('bla', 1);\n"
210             + "      oSelect.options[oSelect.options.length] = oOption;\n"
211             + "      oOption.selected = false;\n"
212             + "      log(oSelect.selectedIndex);\n"
213             + "    }\n"
214             + "  </script>\n"
215             + "</head>\n"
216             + "<body onload='doTest()'>\n"
217             + "  <form action=''>\n"
218             + "    <select id='main'/>\n"
219             + "  </form>\n"
220             + "</body></html>";
221 
222         loadPageVerifyTitle2(html);
223     }
224 
225     /**
226      * @throws Exception if the test fails
227      */
228     @Test
229     @Alerts({"-1", "2", "-1", "-1"})
230     public void setSelectedIndexInvalidValue() throws Exception {
231         final String html = DOCTYPE_HTML
232             + "<html>\n"
233             + "<head>\n"
234             + "  <script>\n"
235             + LOG_TITLE_FUNCTION
236             + "    function doTest() {\n"
237             + "      var s = document.form1.select1;\n"
238             + "      s.selectedIndex = -1;\n"
239             + "      log(s.selectedIndex);\n"
240 
241             + "      s.selectedIndex = 2;\n"
242             + "      log(s.selectedIndex);\n"
243 
244             + "      try { s.selectedIndex = 25; } catch(e) { logEx(e) }\n"
245             + "      log(s.selectedIndex);\n"
246 
247             + "      try { s.selectedIndex = -14; } catch(e) { logEx(e) }\n"
248             + "      log(s.selectedIndex);\n"
249             + "    }\n"
250             + "  </script>\n"
251             + "</head>\n"
252             + "<body onload='doTest()'>\n"
253             + "  <form name='form1' action='http://test' method='get'>\n"
254             + "    <select name='select1'>\n"
255             + "      <option value='option1' name='option1'>One</option>\n"
256             + "      <option value='option2' name='option2' selected>Two</option>\n"
257             + "      <option value='option3' name='option3'>Three</option>\n"
258             + "    </select>\n"
259             + "    <input type='submit' id='clickMe' name='submit' value='button'>\n"
260             + "  </form>\n"
261             + "</body></html>";
262 
263         loadPageVerifyTitle2(html);
264     }
265 
266     /**
267      * @throws Exception if the test fails
268      */
269     @Test
270     @Alerts({"3", "value1", "One", "value2", "Two", "value3", "Three"})
271     public void getOptions() throws Exception {
272         final String html = DOCTYPE_HTML
273             + "<html>\n"
274             + "<head>\n"
275             + "  <script>\n"
276             + LOG_TITLE_FUNCTION
277             + "    function doTest() {\n"
278             + "      var options = document.form1.select1.options;\n"
279             + "      log(options.length);\n"
280             + "      for (var i = 0; i < options.length; i++) {\n"
281             + "        log(options[i].value);\n"
282             + "        log(options[i].text);\n"
283             + "      }\n"
284             + "    }\n"
285             + "  </script>\n"
286             + "</head>\n"
287             + "<body onload='doTest()'>\n"
288             + "  <form name='form1'>\n"
289             + "    <select name='select1'>\n"
290             + "      <option name='option1' value='value1'>One</option>\n"
291             + "      <option name='option2' value='value2' selected>Two</option>\n"
292             + "      <option name='option3' value='value3'>Three</option>\n"
293             + "    </select>\n"
294             + "  </form>\n"
295             + "</body></html>";
296 
297         loadPageVerifyTitle2(html);
298     }
299 
300     /**
301      * @throws Exception if the test fails
302      */
303     @Test
304     @Alerts({"3", "value1", "One", "value2", "Two", "value3", "Three"})
305     public void getOptionLabel() throws Exception {
306         final String html = DOCTYPE_HTML
307             + "<html>\n"
308             + "<head>\n"
309             + "  <script>\n"
310             + LOG_TITLE_FUNCTION
311             + "    function doTest() {\n"
312             + "      var options = document.form1.select1.options;\n"
313             + "      log(options.length);\n"
314             + "      for (var i = 0; i < options.length; i++) {\n"
315             + "        log(options[i].value);\n"
316             + "        log(options[i].text);\n"
317             + "      }\n"
318             + "    }\n"
319             + "  </script>\n"
320             + "</head>\n"
321             + "<body onload='doTest()'>\n"
322             + "  <form name='form1'>\n"
323             + "    <select name='select1'>\n"
324             + "      <option name='option1' value='value1' label='OneLabel'>One</option>\n"
325             + "      <option name='option2' value='value2' label='TwoLabel' selected>Two</option>\n"
326             + "      <option name='option3' value='value3' label='ThreeLabel'>Three</option>\n"
327             + "    </select>\n"
328             + "  </form>\n"
329             + "</body></html>";
330 
331         loadPageVerifyTitle2(html);
332     }
333 
334     /**
335      * @throws Exception if the test fails
336      */
337     @Test
338     @Alerts({"false", "true", "true", "false"})
339     public void getOptionSelected() throws Exception {
340         final String html = DOCTYPE_HTML
341             + "<html>\n"
342             + "<head>\n"
343             + "  <script>\n"
344             + LOG_TITLE_FUNCTION
345             + "    function doTest() {\n"
346             + "      var options = document.form1.select1.options;\n"
347             + "      log(options[0].selected);\n"
348             + "      log(options[1].selected);\n"
349             + "      options[0].selected = true;\n"
350             + "      log(options[0].selected);\n"
351             + "      log(options[1].selected);\n"
352             + "    }\n"
353             + "  </script>\n"
354             + "</head>\n"
355             + "<body onload='doTest()'>\n"
356             + "  <form name='form1'>\n"
357             + "    <select name='select1'>\n"
358             + "      <option name='option1' value='value1'>One</option>\n"
359             + "      <option name='option2' value='value2' selected>Two</option>\n"
360             + "      <option name='option3' value='value3'>Three</option>\n"
361             + "    </select>\n"
362             + "  </form>\n"
363             + "</body></html>";
364 
365         loadPageVerifyTitle2(html);
366     }
367 
368     /**
369      * @throws Exception if the test fails
370      */
371     @Test
372     @Alerts("true")
373     public void getOptionByIndex() throws Exception {
374         final String html = DOCTYPE_HTML
375             + "<html>\n"
376             + "<head>\n"
377             + "  <script>\n"
378             + LOG_TITLE_FUNCTION
379             + "    function doTest() {\n"
380             + "      var option1 = document.f1.elements['select'][0];\n"
381             + "      log(option1 != null);\n"
382             + "    }\n"
383             + "  </script>\n"
384             + "</head>\n"
385             + "<body onload='doTest()'>\n"
386             + "  <form name='f1' action='xxx.html'>\n"
387             + "    <SELECT name='select'>\n"
388             + "      <OPTION value='A'>111</OPTION>\n"
389             + "      <OPTION value='B'>222</OPTION>\n"
390             + "    </SELECT>\n"
391             + "  </form>\n"
392             + "</body></html>";
393 
394         loadPageVerifyTitle2(html);
395     }
396 
397     /**
398      * @throws Exception if the test fails
399      */
400     @Test
401     @Alerts("One")
402     public void getOptionByOptionIndex() throws Exception {
403         final String html = DOCTYPE_HTML
404             + "<html>\n"
405             + "<head>\n"
406             + "  <script>\n"
407             + LOG_TITLE_FUNCTION
408             + "    function doTest() {\n"
409             + "      var option1 = document.form1.select1.options[0];\n"
410             + "      log(option1.text);\n"
411             + "    }\n"
412             + "  </script>\n"
413             + "</head>\n"
414             + "<body onload='doTest()'>\n"
415             + "  <form name='form1'>\n"
416             + "    <select name='select1'>\n"
417             + "      <option name='option1' value='value1'>One</option>\n"
418             + "      <option name='option2' value='value2' selected>Two</option>\n"
419             + "      <option name='option3' value='value3'>Three</option>\n"
420             + "    </select>\n"
421             + "  </form>\n"
422             + "</body></html>";
423 
424         loadPageVerifyTitle2(html);
425     }
426 
427     /**
428      * @throws Exception if the test fails
429      */
430     @Test
431     @Alerts({"4", "Four", "value4"})
432     public void addOption() throws Exception {
433         final String html = DOCTYPE_HTML
434             + "<html>\n"
435             + "<head>\n"
436             + "  <script>\n"
437             + LOG_TITLE_FUNCTION
438             + "    function doTest() {\n"
439             + "      var options = document.form1.select1.options;\n"
440             + "      var index = options.length;\n"
441             + "      options[index] = new Option('Four','value4');\n"
442             + "      log(options.length);\n"
443             + "      log(options[index].text);\n"
444             + "      log(options[index].value);\n"
445             + "    }\n"
446             + "  </script>\n"
447             + "</head>\n"
448             + "<body onload='doTest()'>\n"
449             + "  <form name='form1'>\n"
450             + "    <select name='select1'>\n"
451             + "      <option name='option1' value='value1'>One</option>\n"
452             + "      <option name='option2' value='value2' selected>Two</option>\n"
453             + "      <option name='option3' value='value3'>Three</option>\n"
454             + "    </select>\n"
455             + "  </form>\n"
456             + "</body></html>";
457 
458         loadPageVerifyTitle2(html);
459     }
460 
461     /**
462      * @throws Exception if the test fails
463      */
464     @Test
465     @Alerts({"1", "true", "4", "Four", "value4", "true", "3", "false"})
466     public void addOptionSelected() throws Exception {
467         final String html = DOCTYPE_HTML
468             + "<html>\n"
469             + "<head>\n"
470             + "  <script>\n"
471             + LOG_TITLE_FUNCTION
472             + "    function doTest() {\n"
473             + "      var oSelect = document.form1.select1;\n"
474             + "      var options = oSelect.options;\n"
475             + "      var firstSelectedIndex = oSelect.selectedIndex;\n"
476             + "      log(firstSelectedIndex);\n"
477             + "      log(options[firstSelectedIndex].selected);\n"
478 
479             + "      var index = options.length;\n"
480             + "      var oOption = new Option('Four','value4');\n"
481             + "      oOption.selected = true;\n"
482             + "      options[index] = oOption;\n"
483 
484             + "      log(options.length);\n"
485             + "      log(options[index].text);\n"
486             + "      log(options[index].value);\n"
487             + "      log(options[index].selected);\n"
488             + "      log(oSelect.selectedIndex);\n"
489             + "      log(options[firstSelectedIndex].selected);\n"
490             + "    }\n"
491             + "  </script>\n"
492             + "</head>\n"
493             + "<body onload='doTest()'>\n"
494             + "  <form name='form1'>\n"
495             + "    <select name='select1'>\n"
496             + "      <option name='option1' value='value1'>One</option>\n"
497             + "      <option name='option2' value='value2' selected>Two</option>\n"
498             + "      <option name='option3' value='value3'>Three</option>\n"
499             + "    </select>\n"
500             + "  </form>\n"
501             + "</body></html>";
502 
503         loadPageVerifyTitle2(html);
504     }
505 
506     /**
507      * @throws Exception if the test fails
508      */
509     @Test
510     @Alerts({"4", "Four", "value4"})
511     public void addOptionWithAddMethodIndexNull() throws Exception {
512         final String html = DOCTYPE_HTML
513             + "<html>\n"
514             + "<head>\n"
515             + "  <script>\n"
516             + LOG_TITLE_FUNCTION
517             + "    function doTest() {\n"
518             + "      var options = document.form1.select1;\n"
519             + "      try {\n"
520             + "        options.add(new Option('Four','value4'), null);\n"
521             + "      } catch(e) { logEx(e); }\n"
522             + "      log(options.length);\n"
523             + "      var index = options.length - 1;\n"
524             + "      log(options[index].text);\n"
525             + "      log(options[index].value);\n"
526             + "    }\n"
527             + "  </script>\n"
528             + "</head>\n"
529             + "<body onload='doTest()'>\n"
530             + "  <form name='form1'>\n"
531             + "    <select name='select1'>\n"
532             + "      <option name='option1' value='value1'>One</option>\n"
533             + "      <option name='option2' value='value2' selected>Two</option>\n"
534             + "      <option name='option3' value='value3'>Three</option>\n"
535             + "    </select>\n"
536             + "  </form>\n"
537             + "</body></html>";
538 
539         loadPageVerifyTitle2(html);
540     }
541 
542     /**
543      * Test for bug 1570478.
544      * @throws Exception if the test fails
545      */
546     @Test
547     @Alerts({"4", "Four", "value4", "Three b", "value3b"})
548     public void addOptionWithAddMethodNoSecondParameter() throws Exception {
549         final String html = DOCTYPE_HTML
550             + "<html>\n"
551             + "<head>\n"
552             + "  <script>\n"
553             + LOG_TITLE_FUNCTION
554             + "    function doTest() {\n"
555             + "      var oSelect = document.form1.select1;\n"
556             + "      try {\n"
557             + "        oSelect.add(new Option('Four', 'value4'));\n"
558             + "        log(oSelect.length);\n"
559             + "        log(oSelect[oSelect.length-1].text);\n"
560             + "        log(oSelect[oSelect.length-1].value);\n"
561 
562             + "        oSelect.add(new Option('Three b', 'value3b'), 3);\n"
563             + "        log(oSelect[3].text);\n"
564             + "        log(oSelect[3].value);\n"
565             + "      } catch(e) { logEx(e); }\n"
566             + "    }\n"
567             + "  </script>\n"
568             + "</head>\n"
569             + "<body onload='doTest()'>\n"
570             + "  <form name='form1'>\n"
571             + "    <select name='select1'>\n"
572             + "      <option name='option1' value='value1'>One</option>\n"
573             + "      <option name='option2' value='value2' selected>Two</option>\n"
574             + "      <option name='option3' value='value3'>Three</option>\n"
575             + "    </select>\n"
576             + "  </form>\n"
577             + "</body></html>";
578 
579         loadPageVerifyTitle2(html);
580     }
581 
582     /**
583      * Test for bug 3319397.
584      * @throws Exception if the test fails
585      */
586     @Test
587     @Alerts({"0", "test", "testValue"})
588     public void addOptionTooEmptySelectWithAddMethodIndexNull() throws Exception {
589         final String html = DOCTYPE_HTML
590             + "<html>\n"
591             + "<head>\n"
592             + "  <script>\n"
593             + LOG_TITLE_FUNCTION
594             + "    function doTest() {\n"
595             + "      var oSelect = document.form1.select1;\n"
596             + "      try {\n"
597             + "        log(oSelect.length);\n"
598             + "        oSelect.add(new Option('test', 'testValue'), null);\n"
599             + "        log(oSelect[oSelect.length-1].text);\n"
600             + "        log(oSelect[oSelect.length-1].value);\n"
601             + "      } catch(e) { logEx(e); }\n"
602             + "    }\n"
603             + "  </script>\n"
604             + "</head>\n"
605             + "<body onload='doTest()'>\n"
606             + "  <form name='form1'>\n"
607             + "    <select name='select1'>\n"
608             + "    </select>\n"
609             + "  </form>\n"
610             + "</body></html>";
611 
612         loadPageVerifyTitle2(html);
613     }
614 
615     /**
616      * @throws Exception if the test fails
617      */
618     @Test
619     @Alerts({"0", "1", "0", "foo*"})
620     public void addOptionMethodIndexMinusOneEmptySelect() throws Exception {
621         addOptionMethod(", -1", true, false);
622     }
623 
624     /**
625      * @throws Exception if the test fails
626      */
627     @Test
628     @Alerts({"0", "1", "-1", "foo"})
629     public void addOptionMethodIndexMinusOneEmptySelectMulti() throws Exception {
630         addOptionMethod(", -1", true, true);
631     }
632 
633     /**
634      * @throws Exception if the test fails
635      */
636     @Test
637     @Alerts({"0", "1", "0", "foo*"})
638     public void addOptionMethodIndexZeroEmptySelect() throws Exception {
639         addOptionMethod(", 0", true, false);
640     }
641 
642     /**
643      * @throws Exception if the test fails
644      */
645     @Test
646     @Alerts({"0", "1", "-1", "foo"})
647     public void addOptionMethodIndexZeroEmptySelectMulti() throws Exception {
648         addOptionMethod(", 0", true, true);
649     }
650 
651     /**
652      * @throws Exception if the test fails
653      */
654     @Test
655     @Alerts({"0", "1", "0", "foo*"})
656     public void addOptionMethodIndexOneEmptySelect() throws Exception {
657         addOptionMethod(", 1", true, false);
658     }
659 
660     /**
661      * @throws Exception if the test fails
662      */
663     @Test
664     @Alerts({"0", "1", "-1", "foo"})
665     public void addOptionMethodIndexOneEmptySelectMulti() throws Exception {
666         addOptionMethod(", 1", true, true);
667     }
668 
669     /**
670      * @throws Exception if the test fails
671      */
672     @Test
673     @Alerts({"0", "1", "0", "foo*"})
674     public void addOptionMethodIndexFourEmptySelect() throws Exception {
675         addOptionMethod(", 4", true, false);
676     }
677 
678     /**
679      * @throws Exception if the test fails
680      */
681     @Test
682     @Alerts({"0", "1", "-1", "foo"})
683     public void addOptionMethodIndexFourEmptySelectMulti() throws Exception {
684         addOptionMethod(", 4", true, true);
685     }
686 
687     /**
688      * @throws Exception if the test fails
689      */
690     @Test
691     @Alerts({"3", "4", "1", "One", "Two*", "Three", "foo"})
692     public void addOptionMethodIndexMinusOne() throws Exception {
693         addOptionMethod(", -1", false, false);
694     }
695 
696     /**
697      * @throws Exception if the test fails
698      */
699     @Test
700     @Alerts({"3", "4", "1", "One", "Two*", "Three*", "foo"})
701     public void addOptionMethodIndexMinusOneMulti() throws Exception {
702         addOptionMethod(", -1", false, true);
703     }
704 
705     /**
706      * @throws Exception if the test fails
707      */
708     @Test
709     @Alerts({"3", "4", "2", "foo", "One", "Two*", "Three"})
710     public void addOptionMethodIndexZero() throws Exception {
711         addOptionMethod(", 0", false, false);
712     }
713 
714     /**
715      * @throws Exception if the test fails
716      */
717     @Test
718     @Alerts({"3", "4", "2", "foo", "One", "Two*", "Three*"})
719     public void addOptionMethodIndexZeroMulti() throws Exception {
720         addOptionMethod(", 0", false, true);
721     }
722 
723     /**
724      * @throws Exception if the test fails
725      */
726     @Test
727     @Alerts({"3", "4", "2", "One", "foo", "Two*", "Three"})
728     public void addOptionMethodIndexOne() throws Exception {
729         addOptionMethod(", 1", false, false);
730     }
731 
732     /**
733      * @throws Exception if the test fails
734      */
735     @Test
736     @Alerts({"3", "4", "2", "One", "foo", "Two*", "Three*"})
737     public void addOptionMethodIndexOneMulti() throws Exception {
738         addOptionMethod(", 1", false, true);
739     }
740 
741     /**
742      * @throws Exception if the test fails
743      */
744     @Test
745     @Alerts({"3", "4", "1", "One", "Two*", "foo", "Three"})
746     public void addOptionMethodhIndexTwo() throws Exception {
747         addOptionMethod(", 2", false, false);
748     }
749 
750     /**
751      * @throws Exception if the test fails
752      */
753     @Test
754     @Alerts({"3", "4", "1", "One", "Two*", "foo", "Three*"})
755     public void addOptionMethodhIndexTwoMulti() throws Exception {
756         addOptionMethod(", 2", false, true);
757     }
758 
759     /**
760      * @throws Exception if the test fails
761      */
762     @Test
763     @Alerts({"3", "4", "1", "One", "Two*", "Three", "foo"})
764     public void addOptionMethodIndexThree() throws Exception {
765         addOptionMethod(", 3", false, false);
766     }
767 
768     /**
769      * @throws Exception if the test fails
770      */
771     @Test
772     @Alerts({"3", "4", "1", "One", "Two*", "Three*", "foo"})
773     public void addOptionMethodIndexThreeMulti() throws Exception {
774         addOptionMethod(", 3", false, true);
775     }
776 
777     /**
778      * @throws Exception if the test fails
779      */
780     @Test
781     @Alerts({"3", "4", "1", "One", "Two*", "Three", "foo"})
782     public void addOptionMethodIndexFour() throws Exception {
783         addOptionMethod(", 4", false, false);
784     }
785 
786     /**
787      * @throws Exception if the test fails
788      */
789     @Test
790     @Alerts({"3", "4", "1", "One", "Two*", "Three*", "foo"})
791     public void addOptionMethodIndexFourMulti() throws Exception {
792         addOptionMethod(", 4", false, true);
793     }
794 
795     /**
796      * @throws Exception if the test fails
797      */
798     @Test
799     @Alerts({"0", "1", "0", "foo*"})
800     public void addOptionMethodOptionNullEmptySelect() throws Exception {
801         addOptionMethod(", null", true, false);
802     }
803 
804     /**
805      * @throws Exception if the test fails
806      */
807     @Test
808     @Alerts({"0", "1", "-1", "foo"})
809     public void addOptionMethodOptionNullEmptySelectMulti() throws Exception {
810         addOptionMethod(", null", true, true);
811     }
812 
813     /**
814      * @throws Exception if the test fails
815      */
816     @Test
817     @Alerts({"0", "NotFoundError/DOMException"})
818     public void addOptionMethodNewOptionEmptySelect() throws Exception {
819         addOptionMethod(", new Option('foo', '123')", true, false);
820     }
821 
822     /**
823      * @throws Exception if the test fails
824      */
825     @Test
826     @Alerts({"0", "NotFoundError/DOMException"})
827     public void addOptionMethodNewOptionEmptySelectMulti() throws Exception {
828         addOptionMethod(", new Option('foo', '123')", true, true);
829     }
830 
831     /**
832      * @throws Exception if the test fails
833      */
834     @Test
835     @Alerts({"3", "4", "1", "One", "Two*", "Three", "foo"})
836     public void addOptionMethodOptionNull() throws Exception {
837         addOptionMethod(", null", false, false);
838     }
839 
840     /**
841      * @throws Exception if the test fails
842      */
843     @Test
844     @Alerts({"3", "4", "1", "One", "Two*", "Three*", "foo"})
845     public void addOptionMethodOptionNullMulti() throws Exception {
846         addOptionMethod(", null", false, true);
847     }
848 
849     /**
850      * @throws Exception if the test fails
851      */
852     @Test
853     @Alerts({"3", "NotFoundError/DOMException"})
854     public void addOptionMethodNewOption() throws Exception {
855         addOptionMethod(", new Option('foo', '123')", false, false);
856     }
857 
858     /**
859      * @throws Exception if the test fails
860      */
861     @Test
862     @Alerts({"3", "NotFoundError/DOMException"})
863     public void addOptionMethodNewOptionMulti() throws Exception {
864         addOptionMethod(", new Option('foo', '123')", false, true);
865     }
866 
867     /**
868      * @throws Exception if the test fails
869      */
870     @Test
871     @Alerts({"3", "4", "2", "foo", "One", "Two*", "Three"})
872     public void addOptionMethodOptionFirst() throws Exception {
873         addOptionMethod(", oSelect.options[0]", false, false);
874     }
875 
876     /**
877      * @throws Exception if the test fails
878      */
879     @Test
880     @Alerts({"3", "4", "2", "foo", "One", "Two*", "Three*"})
881     public void addOptionMethodOptionFirstMulti() throws Exception {
882         addOptionMethod(", oSelect.options[0]", false, true);
883     }
884 
885     /**
886      * @throws Exception if the test fails
887      */
888     @Test
889     @Alerts({"3", "4", "2", "One", "foo", "Two*", "Three"})
890     public void addOptionMethodOptionSecond() throws Exception {
891         addOptionMethod(", oSelect.options[1]", false, false);
892     }
893 
894     /**
895      * @throws Exception if the test fails
896      */
897     @Test
898     @Alerts({"3", "4", "2", "One", "foo", "Two*", "Three*"})
899     public void addOptionMethodOptionSecondMulti() throws Exception {
900         addOptionMethod(", oSelect.options[1]", false, true);
901     }
902 
903     /**
904      * @throws Exception if the test fails
905      */
906     @Test
907     @Alerts({"3", "4", "1", "One", "Two*", "foo", "Three"})
908     public void addOptionMethodOptionThird() throws Exception {
909         addOptionMethod(", oSelect.options[2]", false, false);
910     }
911 
912     /**
913      * @throws Exception if the test fails
914      */
915     @Test
916     @Alerts({"3", "4", "1", "One", "Two*", "foo", "Three*"})
917     public void addOptionMethodOptionThirdMulti() throws Exception {
918         addOptionMethod(", oSelect.options[2]", false, true);
919     }
920 
921     /**
922      * @throws Exception if the test fails
923      */
924     @Test
925     @Alerts({"3", "4", "1", "One", "Two*", "Three", "foo"})
926     public void addOptionMethodOptionLast() throws Exception {
927         addOptionMethod(", oSelect.options[3]", false, false);
928     }
929 
930     /**
931      * @throws Exception if the test fails
932      */
933     @Test
934     @Alerts({"3", "4", "1", "One", "Two*", "Three*", "foo"})
935     public void addOptionMethodOptionLastMulti() throws Exception {
936         addOptionMethod(", oSelect.options[3]", false, true);
937     }
938 
939     private void addOptionMethod(final String param, final boolean empty, final boolean multi) throws Exception {
940         String html = DOCTYPE_HTML
941             + "<html>\n"
942             + "<head>\n"
943             + "  <script>\n"
944             + LOG_TITLE_FUNCTION
945             + "    function doTest() {\n"
946             + "      try {\n"
947             + "        var oSelect = document.forms.testForm.select1;\n"
948             + "        log(oSelect.length);\n"
949             + "        var opt = new Option('foo', '123');\n"
950             + "        oSelect.add(opt" + param + ");\n"
951 
952             + "        log(oSelect.length);\n"
953             + "        log(oSelect.selectedIndex);\n"
954             + "        for (var i = 0; i < oSelect.options.length; i++) {\n"
955             + "          log(oSelect.options[i].text + (oSelect.options[i].selected ? '*' : ''));\n"
956             + "        }\n"
957             + "      } catch(e) { logEx(e); }\n"
958             + "    }\n"
959             + "  </script>\n"
960             + "</head>\n"
961             + "<body onload='doTest()'>\n"
962             + "  <form name='testForm'>\n"
963             + "    <select name='select1' " + (multi ? "multiple" : "") + ">\n";
964         if (!empty) {
965             html = html
966                     + "      <option name='option1' value='value1'>One</option>\n"
967                     + "      <option name='option2' value='value2' selected>Two</option>\n"
968                     + "      <option name='option3' value='value3'" + (multi ? "selected" : "") + ">Three</option>\n";
969         }
970         html = html
971             + "    </select>\n"
972             + "  </form>\n"
973             + "</body></html>";
974 
975         loadPageVerifyTitle2(html);
976     }
977 
978     /**
979      * Regression test for bug 308.
980      * See http://sourceforge.net/p/htmlunit/bugs/308/.
981      * @throws Exception if the test fails
982      */
983     @Test
984     @Alerts({"0", "1"})
985     public void addWithIndexEmptySelect() throws Exception {
986         final String html = DOCTYPE_HTML
987             + "<html>\n"
988             + "<head>\n"
989             + "  <script>\n"
990             + LOG_TITLE_FUNCTION
991             + "    function doTest() {\n"
992             + "      try {\n"
993             + "        var oSelect = document.forms.testForm.testSelect;\n"
994             + "        log(oSelect.length);\n"
995             + "        var opt = new Option('foo', '123');\n"
996             + "        oSelect.add(opt, -1);\n"
997             + "        log(oSelect.length);\n"
998             + "      } catch(e) { logEx(e); }\n"
999             + "    }\n"
1000             + "  </script>\n"
1001             + "</head>\n"
1002             + "<body onload='doTest()'>\n"
1003             + "  <form name='testForm'>\n"
1004             + "    <select name='testSelect'></select>\n"
1005             + "  </form>\n"
1006             + "</body></html>";
1007 
1008         loadPageVerifyTitle2(html);
1009     }
1010 
1011     /**
1012      * @throws Exception if the test fails
1013      */
1014     @Test
1015     @Alerts({"0", "0", "-1"})
1016     public void removeOptionMethodIndexMinusOneEmptySelect() throws Exception {
1017         removeOptionMethod("-1", true, false);
1018     }
1019 
1020     /**
1021      * @throws Exception if the test fails
1022      */
1023     @Test
1024     @Alerts({"0", "0", "-1"})
1025     public void removeOptionMethodIndexMinusOneEmptySelectMulti() throws Exception {
1026         removeOptionMethod("-1", true, true);
1027     }
1028 
1029     /**
1030      * @throws Exception if the test fails
1031      */
1032     @Test
1033     @Alerts({"0", "0", "-1"})
1034     public void removeOptionMethodIndexZeroEmptySelect() throws Exception {
1035         removeOptionMethod("0", true, false);
1036     }
1037 
1038     /**
1039      * @throws Exception if the test fails
1040      */
1041     @Test
1042     @Alerts({"0", "0", "-1"})
1043     public void removeOptionMethodIndexZeroEmptySelectMulti() throws Exception {
1044         removeOptionMethod("0", true, true);
1045     }
1046 
1047     /**
1048      * @throws Exception if the test fails
1049      */
1050     @Test
1051     @Alerts({"0", "0", "-1"})
1052     public void removeOptionMethodIndexOneEmptySelect() throws Exception {
1053         removeOptionMethod("1", true, false);
1054     }
1055 
1056     /**
1057      * @throws Exception if the test fails
1058      */
1059     @Test
1060     @Alerts({"0", "0", "-1"})
1061     public void removeOptionMethodIndexOneEmptySelectMulti() throws Exception {
1062         removeOptionMethod("1", true, true);
1063     }
1064 
1065     /**
1066      * @throws Exception if the test fails
1067      */
1068     @Test
1069     @Alerts({"0", "0", "-1"})
1070     public void removeOptionMethodIndexFourEmptySelect() throws Exception {
1071         removeOptionMethod("4", true, false);
1072     }
1073 
1074     /**
1075      * @throws Exception if the test fails
1076      */
1077     @Test
1078     @Alerts({"0", "0", "-1"})
1079     public void removeOptionMethodIndexFourEmptySelectMulti() throws Exception {
1080         removeOptionMethod("4", true, true);
1081     }
1082 
1083     /**
1084      * @throws Exception if the test fails
1085      */
1086     @Test
1087     @Alerts({"3", "3", "1", "One", "Two*", "Three"})
1088     public void removeOptionMethodIndexMinusOne() throws Exception {
1089         removeOptionMethod("-1", false, false);
1090     }
1091 
1092     /**
1093      * @throws Exception if the test fails
1094      */
1095     @Test
1096     @Alerts({"3", "3", "1", "One", "Two*", "Three*"})
1097     public void removeOptionMethodIndexMinusOneMulti() throws Exception {
1098         removeOptionMethod("-1", false, true);
1099     }
1100 
1101     /**
1102      * @throws Exception if the test fails
1103      */
1104     @Test
1105     @Alerts({"3", "2", "0", "Two*", "Three"})
1106     public void removeOptionMethodIndexZero() throws Exception {
1107         removeOptionMethod("0", false, false);
1108     }
1109 
1110     /**
1111      * @throws Exception if the test fails
1112      */
1113     @Test
1114     @Alerts({"3", "2", "0", "Two*", "Three*"})
1115     public void removeOptionMethodIndexZeroMulti() throws Exception {
1116         removeOptionMethod("0", false, true);
1117     }
1118 
1119     /**
1120      * @throws Exception if the test fails
1121      */
1122     @Test
1123     @Alerts({"3", "2", "0", "One*", "Three"})
1124     public void removeOptionMethodIndexOne() throws Exception {
1125         removeOptionMethod("1", false, false);
1126     }
1127 
1128     /**
1129      * @throws Exception if the test fails
1130      */
1131     @Test
1132     @Alerts({"3", "2", "1", "One", "Three*"})
1133     public void removeOptionMethodIndexOneMulti() throws Exception {
1134         removeOptionMethod("1", false, true);
1135     }
1136 
1137     /**
1138      * @throws Exception if the test fails
1139      */
1140     @Test
1141     @Alerts({"3", "2", "1", "One", "Two*"})
1142     public void removeOptionMethodhIndexTwo() throws Exception {
1143         removeOptionMethod("2", false, false);
1144     }
1145 
1146     /**
1147      * @throws Exception if the test fails
1148      */
1149     @Test
1150     @Alerts({"3", "2", "1", "One", "Two*"})
1151     public void removeOptionMethodhIndexTwoMulti() throws Exception {
1152         removeOptionMethod("2", false, true);
1153     }
1154 
1155     /**
1156      * @throws Exception if the test fails
1157      */
1158     @Test
1159     @Alerts({"3", "3", "1", "One", "Two*", "Three"})
1160     public void removeOptionMethodIndexThree() throws Exception {
1161         removeOptionMethod("3", false, false);
1162     }
1163 
1164     /**
1165      * @throws Exception if the test fails
1166      */
1167     @Test
1168     @Alerts({"3", "3", "1", "One", "Two*", "Three*"})
1169     public void removeOptionMethodIndexThreeMulti() throws Exception {
1170         removeOptionMethod("3", false, true);
1171     }
1172 
1173     /**
1174      * @throws Exception if the test fails
1175      */
1176     @Test
1177     @Alerts({"3", "3", "1", "One", "Two*", "Three"})
1178     public void removeOptionMethodIndexFour() throws Exception {
1179         removeOptionMethod("4", false, false);
1180     }
1181 
1182     /**
1183      * @throws Exception if the test fails
1184      */
1185     @Test
1186     @Alerts({"3", "3", "1", "One", "Two*", "Three*"})
1187     public void removeOptionMethodIndexFourMulti() throws Exception {
1188         removeOptionMethod("4", false, true);
1189     }
1190 
1191     /**
1192      * @throws Exception if the test fails
1193      */
1194     @Test
1195     @Alerts({"0", "0", "-1"})
1196     public void removeOptionMethodOptionNullEmptySelect() throws Exception {
1197         removeOptionMethod("null", true, false);
1198     }
1199 
1200     /**
1201      * @throws Exception if the test fails
1202      */
1203     @Test
1204     @Alerts({"0", "0", "-1"})
1205     public void removeOptionMethodOptionNullEmptySelectMulti() throws Exception {
1206         removeOptionMethod("null", true, true);
1207     }
1208 
1209     /**
1210      * @throws Exception if the test fails
1211      */
1212     @Test
1213     @Alerts({"0", "0", "-1"})
1214     public void removeOptionMethodNewOptionEmptySelect() throws Exception {
1215         removeOptionMethod("new Option('foo', '123')", true, false);
1216     }
1217 
1218     /**
1219      * @throws Exception if the test fails
1220      */
1221     @Test
1222     @Alerts({"0", "0", "-1"})
1223     public void removeOptionMethodNewOptionEmptySelectMulti() throws Exception {
1224         removeOptionMethod("new Option('foo', '123')", true, true);
1225     }
1226 
1227     /**
1228      * @throws Exception if the test fails
1229      */
1230     @Test
1231     @Alerts({"3", "2", "0", "Two*", "Three"})
1232     public void removeOptionMethodOptionNull() throws Exception {
1233         removeOptionMethod("null", false, false);
1234     }
1235 
1236     /**
1237      * @throws Exception if the test fails
1238      */
1239     @Test
1240     @Alerts({"3", "2", "0", "Two*", "Three*"})
1241     public void removeOptionMethodOptionNullMulti() throws Exception {
1242         removeOptionMethod("null", false, true);
1243     }
1244 
1245     /**
1246      * @throws Exception if the test fails
1247      */
1248     @Test
1249     @Alerts({"3", "2", "0", "Two*", "Three"})
1250     public void removeOptionMethodNewOption() throws Exception {
1251         removeOptionMethod("new Option('foo', '123')", false, false);
1252     }
1253 
1254     /**
1255      * @throws Exception if the test fails
1256      */
1257     @Test
1258     @Alerts({"3", "2", "0", "Two*", "Three*"})
1259     public void removeOptionMethodNewOptionMulti() throws Exception {
1260         removeOptionMethod("new Option('foo', '123')", false, true);
1261     }
1262 
1263     /**
1264      * @throws Exception if the test fails
1265      */
1266     @Test
1267     @Alerts({"3", "2", "0", "Two*", "Three"})
1268     public void removeOptionMethodOptionFirst() throws Exception {
1269         removeOptionMethod("oSelect.options[0]", false, false);
1270     }
1271 
1272     /**
1273      * @throws Exception if the test fails
1274      */
1275     @Test
1276     @Alerts({"3", "2", "0", "Two*", "Three*"})
1277     public void removeOptionMethodOptionFirstMulti() throws Exception {
1278         removeOptionMethod("oSelect.options[0]", false, true);
1279     }
1280 
1281     /**
1282      * @throws Exception if the test fails
1283      */
1284     @Test
1285     @Alerts({"3", "2", "0", "Two*", "Three"})
1286     public void removeOptionMethodOptionSecond() throws Exception {
1287         removeOptionMethod("oSelect.options[1]", false, false);
1288     }
1289 
1290     /**
1291      * @throws Exception if the test fails
1292      */
1293     @Test
1294     @Alerts({"3", "2", "0", "Two*", "Three*"})
1295     public void removeOptionMethodOptionSecondMulti() throws Exception {
1296         removeOptionMethod("oSelect.options[1]", false, true);
1297     }
1298 
1299     /**
1300      * @throws Exception if the test fails
1301      */
1302     @Test
1303     @Alerts({"3", "2", "0", "Two*", "Three"})
1304     public void removeOptionMethodOptionThird() throws Exception {
1305         removeOptionMethod("oSelect.options[2]", false, false);
1306     }
1307 
1308     /**
1309      * @throws Exception if the test fails
1310      */
1311     @Test
1312     @Alerts({"3", "2", "0", "Two*", "Three*"})
1313     public void removeOptionMethodOptionThirdMulti() throws Exception {
1314         removeOptionMethod("oSelect.options[2]", false, true);
1315     }
1316 
1317     /**
1318      * @throws Exception if the test fails
1319      */
1320     @Test
1321     @Alerts({"3", "2", "0", "Two*", "Three"})
1322     public void removeOptionMethodOptionLast() throws Exception {
1323         removeOptionMethod("oSelect.options[3]", false, false);
1324     }
1325 
1326     /**
1327      * @throws Exception if the test fails
1328      */
1329     @Test
1330     @Alerts({"3", "2", "0", "Two*", "Three*"})
1331     public void removeOptionMethodOptionLastMulti() throws Exception {
1332         removeOptionMethod("oSelect.options[3]", false, true);
1333     }
1334 
1335     private void removeOptionMethod(final String param, final boolean empty, final boolean multi) throws Exception {
1336         String html = DOCTYPE_HTML
1337             + "<html>\n"
1338             + "<head>\n"
1339             + "  <script>\n"
1340             + LOG_TITLE_FUNCTION
1341             + "    function doTest() {\n"
1342             + "      try {\n"
1343             + "        var oSelect = document.forms.testForm.select1;\n"
1344             + "        log(oSelect.length);\n"
1345             + "        oSelect.remove(" + param + ");\n"
1346 
1347             + "        log(oSelect.length);\n"
1348             + "        log(oSelect.selectedIndex);\n"
1349             + "        for (var i = 0; i < oSelect.options.length; i++) {\n"
1350             + "          log(oSelect.options[i].text + (oSelect.options[i].selected ? '*' : ''));\n"
1351             + "        }\n"
1352             + "      } catch(e) { logEx(e); }\n"
1353             + "    }\n"
1354             + "  </script>\n"
1355             + "</head>\n"
1356             + "<body onload='doTest()'>\n"
1357             + "  <form name='testForm'>\n"
1358             + "    <select name='select1' " + (multi ? "multiple" : "") + ">\n";
1359         if (!empty) {
1360             html = html
1361                     + "      <option name='option1' value='value1'>One</option>\n"
1362                     + "      <option name='option2' value='value2' selected>Two</option>\n"
1363                     + "      <option name='option3' value='value3'" + (multi ? "selected" : "") + ">Three</option>\n";
1364         }
1365         html = html
1366             + "    </select>\n"
1367             + "  </form>\n"
1368             + "</body></html>";
1369 
1370         loadPageVerifyTitle2(html);
1371     }
1372 
1373     /**
1374      * @throws Exception if the test fails
1375      */
1376     @Test
1377     @Alerts({"2", "Three", "value3"})
1378     public void removeOption() throws Exception {
1379         final String html = DOCTYPE_HTML
1380             + "<html>\n"
1381             + "<head>\n"
1382             + "<script>\n"
1383             + LOG_TITLE_FUNCTION
1384             + "function doTest() {\n"
1385             + "  var options = document.form1.select1.options;\n"
1386             + "  options[1]=null;\n"
1387             + "  log(options.length);\n"
1388             + "  log(options[1].text);\n"
1389             + "  log(options[1].value);\n"
1390             + "}</script></head><body onload='doTest()'>\n"
1391             + "<p>hello world</p>\n"
1392             + "<form name='form1'>\n"
1393             + "  <select name='select1'>\n"
1394             + "    <option name='option1' value='value1'>One</option>\n"
1395             + "    <option name='option2' value='value2' selected>Two</option>\n"
1396             + "    <option name='option3' value='value3'>Three</option>\n"
1397             + "  </select>\n"
1398             + "</form>\n"
1399             + "</body></html>";
1400 
1401         loadPageVerifyTitle2(html);
1402     }
1403 
1404     /**
1405      * @throws Exception if the test fails
1406      */
1407     @Test
1408     @Alerts({"2", "Three", "value3"})
1409     public void removeOptionWithRemoveMethod() throws Exception {
1410         final String html = DOCTYPE_HTML
1411             + "<html>\n"
1412             + "<head>\n"
1413             + "<script>\n"
1414             + LOG_TITLE_FUNCTION
1415             + "function doTest() {\n"
1416             + "  var select = document.form1.select1;\n"
1417             + "  select.remove(1);\n"
1418             + "  log(select.length);\n"
1419             + "  log(select[1].text);\n"
1420             + "  log(select[1].value);\n"
1421             + "}</script></head><body onload='doTest()'>\n"
1422             + "<p>hello world</p>\n"
1423             + "<form name='form1'>\n"
1424             + "  <select name='select1'>\n"
1425             + "    <option name='option1' value='value1'>One</option>\n"
1426             + "    <option name='option2' value='value2' selected>Two</option>\n"
1427             + "    <option name='option3' value='value3'>Three</option>\n"
1428             + "  </select>\n"
1429             + "</form>\n"
1430             + "</body></html>";
1431 
1432         loadPageVerifyTitle2(html);
1433     }
1434 
1435     /**
1436      * Method remove on the options collection exists only for IE.
1437      * @throws Exception if the test fails
1438      */
1439     @Test
1440     @Alerts({"2", "Three", "value3"})
1441     public void optionsRemoveMethod() throws Exception {
1442         final String html = DOCTYPE_HTML
1443             + "<html>\n"
1444             + "<head>\n"
1445             + "<script>\n"
1446             + LOG_TITLE_FUNCTION
1447             + "function doTest() {\n"
1448             + "  var options = document.form1.select1.options;\n"
1449             + "  try {\n"
1450             + "    options.remove(1);\n"
1451             + "    log(options.length);\n"
1452             + "    log(options[1].text);\n"
1453             + "    log(options[1].value);\n"
1454             + "  } catch(e) { logEx(e); }\n"
1455             + "}</script></head><body onload='doTest()'>\n"
1456             + "<p>hello world</p>\n"
1457             + "<form name='form1'>\n"
1458             + "  <select name='select1'>\n"
1459             + "    <option name='option1' value='value1'>One</option>\n"
1460             + "    <option name='option2' value='value2' selected>Two</option>\n"
1461             + "    <option name='option3' value='value3'>Three</option>\n"
1462             + "  </select>\n"
1463             + "</form>\n"
1464             + "</body></html>";
1465 
1466         loadPageVerifyTitle2(html);
1467     }
1468 
1469     /**
1470      * @throws Exception if the test fails
1471      */
1472     @Test
1473     @Alerts("0")
1474     public void clearOptions() throws Exception {
1475         final String html = DOCTYPE_HTML
1476             + "<html>\n"
1477             + "<head>\n"
1478             + "<script>\n"
1479             + LOG_TITLE_FUNCTION
1480             + "function doTest() {\n"
1481             + "  var options = document.form1.select1.options;\n"
1482             + "  options.length = 0;\n"
1483             + "  log(options.length);\n"
1484             + "}</script></head><body onload='doTest()'>\n"
1485             + "<p>hello world</p>\n"
1486             + "<form name='form1'>\n"
1487             + "  <select name='select1'>\n"
1488             + "    <option name='option1' value='value1'>One</option>\n"
1489             + "    <option name='option2' value='value2' selected>Two</option>\n"
1490             + "    <option name='option3' value='value3'>Three</option>\n"
1491             + "  </select>\n"
1492             + "</form>\n"
1493             + "</body></html>";
1494 
1495         loadPageVerifyTitle2(html);
1496     }
1497 
1498     /**
1499      * Test that option array is filled with empty options when length is increased.
1500      * Test case for bug 1370484
1501      * @throws Exception if the test fails
1502      */
1503     @Test
1504     @Alerts({"1", "2", "", "", "foo", "fooValue"})
1505     public void increaseOptionsSettingLength() throws Exception {
1506         final String html = DOCTYPE_HTML
1507             + "<html>\n"
1508             + "<head>\n"
1509             + "<script>\n"
1510             + LOG_TITLE_FUNCTION
1511             + "function doTest() {\n"
1512             + "  var options = document.form1.select1.options;\n"
1513             + "  log(options.length);\n"
1514             + "  options.length = 2;\n"
1515             + "  log(options.length);\n"
1516             + "  log(options[1].text);\n"
1517             + "  log(options[1].value);\n"
1518             + "  options.length = 50;\n"
1519             + "  options[49].text = 'foo';\n"
1520             + "  options[49].value = 'fooValue';\n"
1521             + "  log(options[49].text);\n"
1522             + "  log(options[49].value);\n"
1523             + "}</script></head><body onload='doTest()'>\n"
1524             + "<p>hello world</p>\n"
1525             + "<form name='form1'>\n"
1526             + "  <select name='select1'>\n"
1527             + "    <option name='option1' value='value1'>One</option>\n"
1528             + "  </select>\n"
1529             + "</form>\n"
1530             + "</body></html>";
1531 
1532         loadPageVerifyTitle2(html);
1533     }
1534 
1535     /**
1536      * @throws Exception if the test fails
1537      */
1538     @Test
1539     @Alerts({"One", "value1"})
1540     public void optionArrayHasItemMethod() throws Exception {
1541         final String html = DOCTYPE_HTML
1542             + "<html>\n"
1543             + "<head>\n"
1544             + "<script>\n"
1545             + LOG_TITLE_FUNCTION
1546             + "function doTest() {\n"
1547             + "  var options = document.form1.select1.options;\n"
1548             + "  log(options.item(0).text);\n"
1549             + "  log(options.item(0).value);\n"
1550             + "}</script></head><body onload='doTest()'>\n"
1551             + "<p>hello world</p>\n"
1552             + "<form name='form1'>\n"
1553             + "  <select name='select1'>\n"
1554             + "    <option name='option1' value='value1'>One</option>\n"
1555             + "    <option name='option2' value='value2' selected>Two</option>\n"
1556             + "    <option name='option3' value='value3'>Three</option>\n"
1557             + "  </select>\n"
1558             + "</form>\n"
1559             + "</body></html>";
1560 
1561         loadPageVerifyTitle2(html);
1562     }
1563 
1564     /**
1565      * @throws Exception if the test fails
1566      */
1567     @Test
1568     @Alerts({"Two", "", "Two", "", ""})
1569     public void getValue() throws Exception {
1570         final String html = DOCTYPE_HTML
1571             + "<html>\n"
1572             + "<head>\n"
1573             + "<script>\n"
1574             + LOG_TITLE_FUNCTION
1575             + "function doTest() {\n"
1576             + "  for (var i = 1; i < 6; i++)\n"
1577             + "  log(document.form1['select' + i].value);\n"
1578             + "}</script></head><body onload='doTest()'>\n"
1579             + "<p>hello world</p>\n"
1580             + "<form name='form1'>\n"
1581             + "  <select name='select1'>\n"
1582             + "    <option name='option1'>One</option>\n"
1583             + "    <option name='option2' selected is='test'>Two</option>\n"
1584             + "    <option name='option3'>Three</option>\n"
1585             + "  </select>\n"
1586             + "  <select name='select2'>\n"
1587             + "  </select>\n"
1588             + "  <select name='select3' multiple>\n"
1589             + "    <option name='option1'>One</option>\n"
1590             + "    <option name='option2' selected>Two</option>\n"
1591             + "    <option name='option3' selected>Three</option>\n"
1592             + "  </select>\n"
1593             + "  <select name='select4' multiple>\n"
1594             + "    <option name='option1'>One</option>\n"
1595             + "    <option name='option2'>Two</option>\n"
1596             + "    <option name='option3'>Three</option>\n"
1597             + "  </select>\n"
1598             + "  <select name='select5' multiple>\n"
1599             + "  </select>\n"
1600             + "</form>\n"
1601             + "</body></html>";
1602 
1603         loadPageVerifyTitle2(html);
1604     }
1605 
1606     /**
1607      * @throws Exception if the test fails
1608      */
1609     @Test
1610     @Alerts({"0", "1"})
1611     public void setValue() throws Exception {
1612         final String html = DOCTYPE_HTML
1613             + "<html>\n"
1614             + "<head><script>\n"
1615             + LOG_TITLE_FUNCTION
1616             + "function doTest() {\n"
1617             + "  log(document.form1.select1.selectedIndex);\n"
1618             + "  document.form1.select1.value = 'option2';\n"
1619             + "  log(document.form1.select1.selectedIndex);\n"
1620             + "}</script></head><body onload='doTest()'>\n"
1621             + "<p>hello world</p>\n"
1622             + "<form name='form1' action='http://test'>\n"
1623             + "  <select name='select1'>\n"
1624             + "    <option value='option1' name='option1'>One</option>\n"
1625             + "    <option value='option2' name='option2'>Two</option>\n"
1626             + "  </select>\n"
1627             + "</form>\n"
1628             + "</body></html>";
1629 
1630         loadPageVerifyTitle2(html);
1631     }
1632 
1633     /**
1634      * Test that options delegates to select (bug 1111597).
1635      * @throws Exception if the test fails
1636      */
1637     @Test
1638     @Alerts("TypeError")
1639     public void optionsDelegateToSelect() throws Exception {
1640         final String html = DOCTYPE_HTML
1641             + "<html>\n"
1642             + "<head>\n"
1643             + "<script>\n"
1644             + LOG_TITLE_FUNCTION
1645             + "function doTest() {\n"
1646             + "  try {\n"
1647             + "    var s = document.getElementById('select1');\n"
1648             + "    doAlerts(s);\n"
1649             + "\n"
1650             + "    s.selectedIndex = 0;\n"
1651             + "    doAlerts(s);\n"
1652             + "\n"
1653             + "    s.options.selectedIndex = 1;\n"
1654             + "    doAlerts(s);\n"
1655             + "  } catch(e) { logEx(e); }\n"
1656             + "}\n"
1657             + "function doAlerts(s) {\n"
1658             + "  log(s.childNodes.length + '-' + s.options.childNodes.length);\n"
1659             + "  log(s.selectedIndex + '-' + s.options.selectedIndex);\n"
1660             + "}\n"
1661             + "</script>\n"
1662             + "</head>\n"
1663             + "<body onload='doTest()'>\n"
1664             + "<form name='test'>\n"
1665             + "  <select id='select1'><option>a</option><option selected='selected'>b</option></select>\n"
1666             + "</form>\n"
1667             + "</body></html>";
1668 
1669         loadPageVerifyTitle2(html);
1670     }
1671 
1672     /**
1673      * Test that options delegates to select (bug 1111597).
1674      * @throws Exception if the test fails
1675      */
1676     @Test
1677     @Alerts({"2", "b", "3", "c"})
1678     public void optionsArrayAdd() throws Exception {
1679         final String html = DOCTYPE_HTML
1680             + "<html>\n"
1681             + "<head>\n"
1682             + "<script>\n"
1683             + LOG_TITLE_FUNCTION
1684             + "function doTest() {\n"
1685             + "  var s = document.getElementById('select1');\n"
1686             + "  var lengthBefore = s.options.length;\n"
1687             + "  log(lengthBefore);\n"
1688             + "  log(s.options.item(lengthBefore - 1).text);\n"
1689             + "  var opt = document.createElement(\"OPTION\");\n"
1690             + "  opt.value = 'c';\n"
1691             + "  opt.text = 'c';\n"
1692             + "  s.options.add(opt);\n"
1693             + "  var lengthAfterAdd = s.options.length;\n"
1694             + "  log(lengthAfterAdd);\n"
1695             + "  log(s.options.item(lengthAfterAdd - 1).text);\n"
1696             + "}\n"
1697             + "</script>\n"
1698             + "</head>\n"
1699             + "<body onload='doTest()'>\n"
1700             + "<form name='test'>\n"
1701             + "<select id='select1'>\n"
1702             + "<option>a</option>\n"
1703             + "<option selected='selected'>b</option>\n"
1704             + "</select></form>\n"
1705             + "</body></html>";
1706 
1707         loadPageVerifyTitle2(html);
1708     }
1709 
1710     /**
1711      * @throws Exception if the test fails
1712      */
1713     @Test
1714     @Alerts("-1")
1715     public void selectedIndex() throws Exception {
1716         final String html = DOCTYPE_HTML
1717             + "<html>\n"
1718             + "<head>\n"
1719             + "<script>\n"
1720             + LOG_TITLE_FUNCTION
1721             + "  function test() {\n"
1722             + "    var s = document.getElementById('mySelect');\n"
1723             + "    s.options.length = 0;\n"
1724             + "    s.selectedIndex = 0;\n"
1725             + "    log(s.selectedIndex);\n"
1726             + "  }\n"
1727             + "</script>\n"
1728             + "</head>\n"
1729             + "<body onload='test()'>\n"
1730             + "  <select id='mySelect'><option>hello</option></select>\n"
1731             + "</body></html>";
1732 
1733         loadPageVerifyTitle2(html);
1734     }
1735 
1736     /**
1737      * @throws Exception if the test fails
1738      */
1739     @Test
1740     @Alerts({"0", "true", "false", "false", "0"})
1741     public void defaultSelectedValue_SizeNegativeOne() throws Exception {
1742         defaultSelectedValue("-1", false);
1743     }
1744 
1745     /**
1746      * @throws Exception if the test fails
1747      */
1748     @Test
1749     @Alerts({"0", "false", "false", "false", "-1"})
1750     public void defaultSelectedValue_SizeNegativeOne_Multi() throws Exception {
1751         defaultSelectedValue("-1", true);
1752     }
1753 
1754     /**
1755      * @throws Exception if the test fails
1756      */
1757     @Test
1758     @Alerts({"0", "true", "false", "false", "0"})
1759     public void defaultSelectedValue_SizeZero() throws Exception {
1760         defaultSelectedValue("0", false);
1761     }
1762 
1763     /**
1764      * @throws Exception if the test fails
1765      */
1766     @Test
1767     @Alerts({"0", "false", "false", "false", "-1"})
1768     public void defaultSelectedValue_SizeZero_Multi() throws Exception {
1769         defaultSelectedValue("0", true);
1770     }
1771 
1772     /**
1773      * @throws Exception if the test fails
1774      */
1775     @Test
1776     @Alerts({"1", "true", "false", "false", "0"})
1777     public void defaultSelectedValue_SizeOne() throws Exception {
1778         defaultSelectedValue("1", false);
1779     }
1780 
1781     /**
1782      * @throws Exception if the test fails
1783      */
1784     @Test
1785     @Alerts({"1", "false", "false", "false", "-1"})
1786     public void defaultSelectedValue_SizeOne_Multi() throws Exception {
1787         defaultSelectedValue("1", true);
1788     }
1789 
1790     /**
1791      * @throws Exception if the test fails
1792      */
1793     @Test
1794     @Alerts({"2", "false", "false", "false", "-1"})
1795     public void defaultSelectedValue_SizeTwo() throws Exception {
1796         defaultSelectedValue("2", false);
1797     }
1798 
1799     /**
1800      * @throws Exception if the test fails
1801      */
1802     @Test
1803     @Alerts({"2", "false", "false", "false", "-1"})
1804     public void defaultSelectedValue_SizeTwo_Multi() throws Exception {
1805         defaultSelectedValue("2", true);
1806     }
1807 
1808     /**
1809      * @throws Exception if the test fails
1810      */
1811     @Test
1812     @Alerts({"0", "true", "false", "false", "0"})
1813     public void defaultSelectedValue_SizeInvalid() throws Exception {
1814         defaultSelectedValue("x", false);
1815     }
1816 
1817     /**
1818      * @throws Exception if the test fails
1819      */
1820     @Test
1821     @Alerts({"0", "false", "false", "false", "-1"})
1822     public void defaultSelectedValue_SizeInvalid_Mulzi() throws Exception {
1823         defaultSelectedValue("x", true);
1824     }
1825 
1826     /**
1827      * Tests default selection status for options in a select of the specified size, optionally
1828      * allowing multiple selections.
1829      * @param size the select input's size attribute
1830      * @param multiple whether or not the select input should allow multiple selections
1831      * @param expected the expected alerts
1832      * @throws Exception if the test fails
1833      */
1834     private void defaultSelectedValue(final String size, final boolean multiple)
1835         throws Exception {
1836 
1837         final String html = DOCTYPE_HTML
1838             + "<html>\n"
1839             + "<body onload='test()'>\n"
1840             + "<script>\n"
1841             + LOG_TITLE_FUNCTION
1842             + "   function test() {\n"
1843             + "     log(document.getElementById('s').size);\n"
1844             + "     log(document.getElementById('a').selected);\n"
1845             + "     log(document.getElementById('b').selected);\n"
1846             + "     log(document.getElementById('c').selected);\n"
1847             + "     log(document.getElementById('s').selectedIndex);\n"
1848             + "   }\n"
1849             + "</script>\n"
1850             + "<form id='f'>\n"
1851             + "  <select id='s' size='" + size + "'" + (multiple ? " multiple" : "") + ">\n"
1852             + "    <option id='a' value='a'>a</option>\n"
1853             + "    <option id='b' value='b'>b</option>\n"
1854             + "    <option id='c' value='c'>c</option>\n"
1855             + "  </select>\n"
1856             + "</form>\n"
1857             + "</body></html>";
1858 
1859         loadPageVerifyTitle2(html);
1860     }
1861 
1862     /**
1863      * @throws Exception if the test fails
1864      */
1865     @Test
1866     @Alerts("5")
1867     public void size() throws Exception {
1868         final String html = DOCTYPE_HTML
1869             + "<html>\n"
1870             + "<head>\n"
1871             + "<script>\n"
1872             + LOG_TITLE_FUNCTION
1873             + "  function test() {\n"
1874             + "    var select = document.getElementById('mySelect');\n"
1875             + "    log(select.size + 5);//to test if int or string\n"
1876             + "  }\n"
1877             + "</script>\n"
1878             + "</head>\n"
1879             + "<body onload='test()'>\n"
1880             + "  <select id='mySelect'/>\n"
1881             + "</body></html>";
1882 
1883         loadPageVerifyTitle2(html);
1884     }
1885 
1886     /**
1887      * @throws Exception if an error occurs
1888      */
1889     @Test
1890     @Alerts({"true", "false", "false"})
1891     public void multiple() throws Exception {
1892         final String html = DOCTYPE_HTML
1893             + "<html>\n"
1894             + "<head>\n"
1895             + "<script>\n"
1896             + LOG_TITLE_FUNCTION
1897             + "  function test() {\n"
1898             + "    log(document.f['s1'].multiple);\n"
1899             + "    log(document.f['s2'].multiple);\n"
1900             + "    document.f['s1'].multiple = false;\n"
1901             + "    log(document.f['s1'].multiple);\n"
1902             + "  }\n"
1903             + "</script>\n"
1904             + "</head>\n"
1905             + "<body onload='test()'>\n"
1906             + "  <form name='f'>\n"
1907             + "    <select name='s1' multiple>\n"
1908             + "      <option name='option1'>One</option>\n"
1909             + "      <option name='option2'>Two</option>\n"
1910             + "      <option name='option3'>Three</option>\n"
1911             + "    </select>\n"
1912             + "    <select name='s2'>\n"
1913             + "      <option name='option4'>Four</option>\n"
1914             + "      <option name='option5'>Five</option>\n"
1915             + "      <option name='option6'>Six</option>\n"
1916             + "    </select>\n"
1917             + "  </form>\n"
1918             + "</body></html>";
1919 
1920         loadPageVerifyTitle2(html);
1921     }
1922 
1923     /**
1924      * @throws Exception if an error occurs
1925      */
1926     @Test
1927     public void deselectMultiple() throws Exception {
1928         final String html = DOCTYPE_HTML
1929             + "<html>\n"
1930             + "<body>\n"
1931             + "  <form name='f'>\n"
1932             + "    <select name='s1' multiple>\n"
1933             + "      <option name='option1'>One</option>\n"
1934             + "      <option id='it' name='option2' selected='true'>Two</option>\n"
1935             + "      <option name='option3'>Three</option>\n"
1936             + "    </select>\n"
1937             + "  </form>\n"
1938             + "</body></html>";
1939 
1940         final WebDriver webdriver = loadPage2(html);
1941         final WebElement firstOption = webdriver.findElement(By.id("it"));
1942         assertTrue(firstOption.isSelected());
1943         firstOption.click();
1944         assertFalse(firstOption.isSelected());
1945     }
1946 
1947     /**
1948      * @throws Exception if the test fails
1949      */
1950     @Test
1951     @Alerts({"0", "1"})
1952     public void selectedIndex_onfocus() throws Exception {
1953         final String html = DOCTYPE_HTML
1954             + "<html>\n"
1955             + "<head>\n"
1956             + "<script>\n"
1957             + LOG_TITLE_FUNCTION
1958             + "  function test() {\n"
1959             + "    var s = document.getElementById('mySelect');\n"
1960             + "    log(s.selectedIndex);\n"
1961             + "    s.selectedIndex = 1;\n"
1962             + "    log(s.selectedIndex);\n"
1963             + "  }\n"
1964             + "</script>\n"
1965             + "</head>\n"
1966             + "<body onload='test()'>\n"
1967             + "  <select id='mySelect' onfocus='log(\"select-focus\")'>\n"
1968             + "    <option value='o1'>hello</option>\n"
1969             + "    <option value='o2'>there</option>\n"
1970             + "  </select>\n"
1971             + "</body></html>";
1972 
1973         loadPageVerifyTitle2(html);
1974     }
1975 
1976     /**
1977      * @throws Exception if the test fails
1978      */
1979     @Test
1980     @Alerts({"o1", "o2"})
1981     public void value_onfocus() throws Exception {
1982         final String html = DOCTYPE_HTML
1983             + "<html>\n"
1984             + "<head>\n"
1985             + "<script>\n"
1986             + LOG_TITLE_FUNCTION
1987             + "  function test() {\n"
1988             + "    var s = document.getElementById('mySelect');\n"
1989             + "    log(s.value);\n"
1990             + "    s.value = 'o2';\n"
1991             + "    log(s.value);\n"
1992             + "  }\n"
1993             + "</script>\n"
1994             + "</head>\n"
1995             + "<body onload='test()'>\n"
1996             + "  <select id='mySelect' onfocus='log(\"select-focus\")'>\n"
1997             + "    <option value='o1'>hello</option>\n"
1998             + "    <option value='o2'>there</option>\n"
1999             + "  </select>\n"
2000             + "</body></html>";
2001 
2002         loadPageVerifyTitle2(html);
2003     }
2004 
2005     /**
2006      * @throws Exception if the test fails
2007      */
2008     @Test
2009     @Alerts({"-1", "0", "-1"})
2010     public void selectedIndex_appendChild() throws Exception {
2011         final String html = DOCTYPE_HTML
2012             + "<html>\n"
2013             + "<head>\n"
2014             + "<script>\n"
2015             + LOG_TITLE_FUNCTION
2016             + "  function test() {\n"
2017             + "    var s = document.getElementById('mySelect');\n"
2018             + "    var o = document.createElement('option');\n"
2019             + "    log(s.selectedIndex);\n"
2020             + "    s.appendChild(o);\n"
2021             + "    log(s.selectedIndex);\n"
2022             + "    s.removeChild(o);\n"
2023             + "    log(s.selectedIndex);\n"
2024             + "  }\n"
2025             + "</script>\n"
2026             + "</head>\n"
2027             + "<body onload='test()'>\n"
2028             + "  <select id='mySelect'></select>\n"
2029             + "</body></html>";
2030 
2031         loadPageVerifyTitle2(html);
2032     }
2033 
2034     /**
2035      * @throws Exception if the test fails
2036      */
2037     @Test
2038     @Alerts({"-1", "0", "-1"})
2039     public void selectedIndex_insertBefore() throws Exception {
2040         final String html = DOCTYPE_HTML
2041             + "<html>\n"
2042             + "<head>\n"
2043             + "<script>\n"
2044             + LOG_TITLE_FUNCTION
2045             + "  function test() {\n"
2046             + "    var s = document.getElementById('mySelect');\n"
2047             + "    var o = document.createElement('option');\n"
2048             + "    log(s.selectedIndex);\n"
2049             + "    s.insertBefore(o, null);\n"
2050             + "    log(s.selectedIndex);\n"
2051             + "    s.removeChild(o);\n"
2052             + "    log(s.selectedIndex);\n"
2053             + "  }\n"
2054             + "</script>\n"
2055             + "</head>\n"
2056             + "<body onload='test()'>\n"
2057             + "  <select id='mySelect'></select>\n"
2058             + "</body></html>";
2059 
2060         loadPageVerifyTitle2(html);
2061     }
2062 
2063     /**
2064      * @throws Exception if the test fails
2065      */
2066     @Test
2067     @Alerts({"0", "1", "0"})
2068     public void selectedIndex_insertBeforeExisting() throws Exception {
2069         final String html = DOCTYPE_HTML
2070             + "<html>\n"
2071             + "<head>\n"
2072             + "<script>\n"
2073             + LOG_TITLE_FUNCTION
2074             + "  function test() {\n"
2075             + "    var s = document.getElementById('mySelect');\n"
2076             + "    var o1 = document.getElementById('option1');\n"
2077             + "    var o = document.createElement('option');\n"
2078             + "    log(s.selectedIndex);\n"
2079 
2080             + "    s.insertBefore(o, o1);\n"
2081             + "    log(s.selectedIndex);\n"
2082 
2083             + "    s.removeChild(o1);\n"
2084             + "    log(s.selectedIndex);\n"
2085             + "  }\n"
2086             + "</script>\n"
2087             + "</head>\n"
2088             + "<body onload='test()'>\n"
2089             + "  <select id='mySelect'>\n"
2090             + "    <option id='option1'>option1</option>"
2091             + "  </select>\n"
2092             + "</body></html>";
2093 
2094         loadPageVerifyTitle2(html);
2095     }
2096 
2097     /**
2098      * @throws Exception if the test fails
2099      */
2100     @Test
2101     @Alerts({"-1", "0", "-1"})
2102     public void selectedIndex_add() throws Exception {
2103         final String html = DOCTYPE_HTML
2104             + "<html>\n"
2105             + "<head>\n"
2106             + "<script>\n"
2107             + LOG_TITLE_FUNCTION
2108             + "  function test() {\n"
2109             + "    var s = document.getElementById('mySelect');\n"
2110             + "    var o = document.createElement('option');\n"
2111             + "    log(s.selectedIndex);\n"
2112             + "    if (document.all)\n"
2113             + "      s.add(o);\n"
2114             + "    else\n"
2115             + "      s.add(o, null);\n"
2116             + "    log(s.selectedIndex);\n"
2117             + "    s.removeChild(o);\n"
2118             + "    log(s.selectedIndex);\n"
2119             + "  }\n"
2120             + "</script>\n"
2121             + "</head>\n"
2122             + "<body onload='test()'>\n"
2123             + "  <select id='mySelect'></select>\n"
2124             + "</body></html>";
2125 
2126         loadPageVerifyTitle2(html);
2127     }
2128 
2129     /**
2130      * @throws Exception if the test fails
2131      */
2132     @Test
2133     @Alerts({"first", "null", "null"})
2134     public void item() throws Exception {
2135         final String html = DOCTYPE_HTML
2136             + "<html>\n"
2137             + "<body>\n"
2138             + "  <select id='mySelect'>\n"
2139             + "    <option>first</option>\n"
2140             + "    <option>second</option>\n"
2141             + "  </select>\n"
2142 
2143             + "  <script>\n"
2144             + LOG_TITLE_FUNCTION
2145             + "    var s = document.getElementById('mySelect');\n"
2146             + "    log(s.item(0).text);\n"
2147             + "    log(s.item(300));\n"
2148             + "    try { log(s.item(-5)); } catch(e) { logEx(e); }\n"
2149             + "  </script>\n"
2150             + "</body></html>";
2151 
2152         loadPageVerifyTitle2(html);
2153     }
2154 
2155     /**
2156      * @throws Exception if the test fails
2157      */
2158     @Test
2159     @Alerts({"two", ""})
2160     public void value() throws Exception {
2161         final String html = DOCTYPE_HTML
2162             + "<html>\n"
2163             + "<head>\n"
2164             + "<script>\n"
2165             + LOG_TITLE_FUNCTION
2166             + "  function test() {\n"
2167             + "    var select = document.getElementById('mySelect');\n"
2168             + "    log(select.value);\n"
2169             + "    select.value = 'three';\n"
2170             + "    log(select.value);\n"
2171             + "  }\n"
2172             + "</script>\n"
2173             + "</head>\n"
2174             + "<body onload='test()'>\n"
2175             + "  <select id='mySelect'>\n"
2176             + "    <option value='one'>One</option>\n"
2177             + "    <option selected value='two'>Two</option>\n"
2178             + "  </select>\n"
2179             + "</body></html>";
2180         loadPageVerifyTitle2(html);
2181     }
2182 
2183     /**
2184      * @throws Exception if the test fails
2185      */
2186     @Test
2187     @Alerts({"two", "one"})
2188     public void valueByValue() throws Exception {
2189         final String html = DOCTYPE_HTML
2190             + "<html>\n"
2191             + "<head>\n"
2192             + "<script>\n"
2193             + LOG_TITLE_FUNCTION
2194             + "  function test() {\n"
2195             + "    var select = document.getElementById('mySelect');\n"
2196             + "    log(select.value);\n"
2197             + "    select.value = 'one';\n"
2198             + "    log(select.value);\n"
2199             + "  }\n"
2200             + "</script>\n"
2201             + "</head>\n"
2202             + "<body onload='test()'>\n"
2203             + "  <select id='mySelect'>\n"
2204             + "    <option value='one'>1</option>\n"
2205             + "    <option selected value='two'>2</option>\n"
2206             + "  </select>\n"
2207             + "</body></html>";
2208         loadPageVerifyTitle2(html);
2209     }
2210 
2211     /**
2212      * @throws Exception if the test fails
2213      */
2214     @Test
2215     @Alerts({"two", ""})
2216     public void valueByValueCase() throws Exception {
2217         final String html = DOCTYPE_HTML
2218             + "<html>\n"
2219             + "<head>\n"
2220             + "<script>\n"
2221             + LOG_TITLE_FUNCTION
2222             + "  function test() {\n"
2223             + "    var select = document.getElementById('mySelect');\n"
2224             + "    log(select.value);\n"
2225             + "    select.value = 'One';\n"
2226             + "    log(select.value);\n"
2227             + "  }\n"
2228             + "</script>\n"
2229             + "</head>\n"
2230             + "<body onload='test()'>\n"
2231             + "  <select id='mySelect'>\n"
2232             + "    <option value='one'>1</option>\n"
2233             + "    <option selected value='two'>2</option>\n"
2234             + "  </select>\n"
2235             + "</body></html>";
2236         loadPageVerifyTitle2(html);
2237     }
2238 
2239     /**
2240      * @throws Exception if the test fails
2241      */
2242     @Test
2243     @Alerts({"two", "One"})
2244     public void valueByText() throws Exception {
2245         final String html = DOCTYPE_HTML
2246             + "<html>\n"
2247             + "<head>\n"
2248             + "<script>\n"
2249             + LOG_TITLE_FUNCTION
2250             + "  function test() {\n"
2251             + "    var select = document.getElementById('mySelect');\n"
2252             + "    log(select.value);\n"
2253             + "    select.value = 'One';\n"
2254             + "    log(select.value);\n"
2255             + "  }\n"
2256             + "</script>\n"
2257             + "</head>\n"
2258             + "<body onload='test()'>\n"
2259             + "  <select id='mySelect'>\n"
2260             + "    <option>One</option>\n"
2261             + "    <option selected value='two'>Two</option>\n"
2262             + "  </select>\n"
2263             + "</body></html>";
2264 
2265         loadPageVerifyTitle2(html);
2266     }
2267 
2268     /**
2269      * @throws Exception if the test fails
2270      */
2271     @Test
2272     @Alerts({"two", "One"})
2273     public void valueByTextTrim() throws Exception {
2274         final String html = DOCTYPE_HTML
2275             + "<html>\n"
2276             + "<head>\n"
2277             + "<script>\n"
2278             + LOG_TITLE_FUNCTION
2279             + "  function test() {\n"
2280             + "    var select = document.getElementById('mySelect');\n"
2281             + "    log(select.value);\n"
2282             + "    select.value = 'One';\n"
2283             + "    log(select.value);\n"
2284             + "  }\n"
2285             + "</script>\n"
2286             + "</head>\n"
2287             + "<body onload='test()'>\n"
2288             + "  <select id='mySelect'>\n"
2289             + "    <option> One </option>\n"
2290             + "    <option selected value='two'>Two</option>\n"
2291             + "  </select>\n"
2292             + "</body></html>";
2293         loadPageVerifyTitle2(html);
2294     }
2295 
2296     /**
2297      * @throws Exception if the test fails
2298      */
2299     @Test
2300     @Alerts({"two", ""})
2301     public void valueNull() throws Exception {
2302         final String html = DOCTYPE_HTML
2303             + "<html>\n"
2304             + "<head>\n"
2305             + "<script>\n"
2306             + LOG_TITLE_FUNCTION
2307             + "  function test() {\n"
2308             + "    var select = document.getElementById('mySelect');\n"
2309             + "    log(select.value);\n"
2310             + "    select.value = null;\n"
2311             + "    log(select.value);\n"
2312             + "  }\n"
2313             + "</script>\n"
2314             + "</head>\n"
2315             + "<body onload='test()'>\n"
2316             + "  <select id='mySelect'>\n"
2317             + "    <option>One</option>\n"
2318             + "    <option selected value='two'>Two</option>\n"
2319             + "  </select>\n"
2320             + "</body></html>";
2321 
2322         loadPageVerifyTitle2(html);
2323     }
2324 
2325     /**
2326      * @throws Exception if the test fails
2327      */
2328     @Test
2329     @Alerts({"two", "", ""})
2330     public void valueOther() throws Exception {
2331         final String html = DOCTYPE_HTML
2332             + "<html>\n"
2333             + "<head>\n"
2334             + "<script>\n"
2335             + LOG_TITLE_FUNCTION
2336             + "  function test() {\n"
2337             + "    var select = document.getElementById('mySelect');\n"
2338             + "    log(select.value);\n"
2339             + "    select.value = 1234;\n"
2340             + "    log(select.value);\n"
2341             + "    select.value = select;\n"
2342             + "    log(select.value);\n"
2343             + "  }\n"
2344             + "</script>\n"
2345             + "</head>\n"
2346             + "<body onload='test()'>\n"
2347             + "  <select id='mySelect'>\n"
2348             + "    <option>One</option>\n"
2349             + "    <option selected value='two'>Two</option>\n"
2350             + "  </select>\n"
2351             + "</body></html>";
2352 
2353         loadPageVerifyTitle2(html);
2354     }
2355 
2356     /**
2357      * @throws Exception if the test fails
2358      */
2359     @Test
2360     @Alerts({"One", "Two", "One"})
2361     public void valueAfterReset() throws Exception {
2362         final String html = DOCTYPE_HTML
2363             + "<html>\n"
2364             + "<head>\n"
2365             + "<script>\n"
2366             + LOG_TITLE_FUNCTION
2367             + "  function test() {\n"
2368             + "    var form = document.getElementById('myForm');\n"
2369             + "    var select = document.getElementById('mySelect');\n"
2370             + "    log(select.value);\n"
2371             + "    select.options[1].selected = true;\n"
2372             + "    log(select.value);\n"
2373             + "    form.reset();\n"
2374             + "    log(select.value);\n"
2375             + "  }\n"
2376             + "</script>\n"
2377             + "</head>\n"
2378             + "<body onload='test()'>\n"
2379             + "<form id='myForm' name='myForm'>\n"
2380             + "  <select id='mySelect'>\n"
2381             + "    <option value='One'>One</option>\n"
2382             + "    <option value='Two'>Two</option>\n"
2383             + "  </select>\n"
2384             + "</form>\n"
2385             + "</body></html>";
2386 
2387         loadPageVerifyTitle2(html);
2388     }
2389 
2390     /**
2391      * @throws Exception if an error occurs
2392      */
2393     @Test
2394     @Alerts("mouse over")
2395     @BuggyWebDriver(FF = "mouse overmouse overmouse over",
2396             FF_ESR = "mouse overmouse overmouse over")
2397     public void mouseOver() throws Exception {
2398         final String html = DOCTYPE_HTML
2399             + "<html>\n"
2400             + "  <head>\n"
2401             + "    <script>\n"
2402             + "    function doTest() {\n"
2403             + "      document.title += 'mouse over';\n"
2404             + "    }\n"
2405             + "    </script>\n"
2406             + "  </head>\n"
2407             + "<body>\n"
2408             + "  <form id='form1'>\n"
2409             + "    <select name='select1' id='select1' size='4' onmouseover='doTest()'>\n"
2410             + "      <option value='option1' id='option1' >Option1</option>\n"
2411             + "      <option value='option2' id='option2'>Option2</option>\n"
2412             + "    </select>\n"
2413             + "  </form>\n"
2414             + "</body></html>";
2415 
2416         final WebDriver driver = loadPage2(html);
2417         final Actions actions = new Actions(driver);
2418         actions.moveToElement(driver.findElement(By.id("select1")));
2419         actions.perform();
2420         Thread.sleep(400);
2421 
2422         assertTitle(driver, getExpectedAlerts()[0]);
2423     }
2424 
2425     /**
2426      * @throws Exception if an error occurs
2427      */
2428     @Test
2429     @Alerts("mouse over")
2430     @BuggyWebDriver(FF = "mouse overmouse overmouse over",
2431             FF_ESR = "mouse overmouse overmouse over")
2432     public void mouseOverDisabledSelect() throws Exception {
2433         final String html = DOCTYPE_HTML
2434             + "<html>\n"
2435             + "  <head>\n"
2436             + "    <script>\n"
2437             + "    function doTest() {\n"
2438             + "      document.title += 'mouse over';\n"
2439             + "    }\n"
2440             + "    </script>\n"
2441             + "  </head>\n"
2442             + "<body>\n"
2443             + "  <form id='form1'>\n"
2444             + "    <select name='select1' id='select1' size='4' onmouseover='doTest()' disabled='disabled'>\n"
2445             + "      <option value='option1' id='option1'>Option1</option>\n"
2446             + "      <option value='option2' id='option2'>Option2</option>\n"
2447             + "    </select>\n"
2448             + "  </form>\n"
2449             + "</body></html>";
2450 
2451         final WebDriver driver = loadPage2(html);
2452         final Actions actions = new Actions(driver);
2453         actions.moveToElement(driver.findElement(By.id("select1")));
2454         actions.perform();
2455         Thread.sleep(400);
2456 
2457         assertTitle(driver, getExpectedAlerts()[0]);
2458     }
2459 
2460     /**
2461      * @throws Exception if an error occurs
2462      */
2463     @Test
2464     @Alerts({"0", "2", "1", "2", "1", "1"})
2465     public void labels() throws Exception {
2466         final String html = DOCTYPE_HTML
2467             + "<html><head>\n"
2468             + "  <script>\n"
2469             + LOG_TITLE_FUNCTION
2470             + "    function test() {\n"
2471             + "      debug(document.getElementById('e1'));\n"
2472             + "      debug(document.getElementById('e2'));\n"
2473             + "      debug(document.getElementById('e3'));\n"
2474             + "      debug(document.getElementById('e4'));\n"
2475             + "      var labels = document.getElementById('e4').labels;\n"
2476             + "      document.body.removeChild(document.getElementById('l4'));\n"
2477             + "      debug(document.getElementById('e4'));\n"
2478             + "      log(labels ? labels.length : labels);\n"
2479             + "    }\n"
2480             + "    function debug(e) {\n"
2481             + "      log(e.labels ? e.labels.length : e.labels);\n"
2482             + "    }\n"
2483             + "  </script>\n"
2484             + "</head>\n"
2485             + "<body onload='test()'>\n"
2486             + "  <select id='e1'>e 1</select><br>\n"
2487             + "  <label>something <label> click here <select id='e2'>e 2</select></label></label><br>\n"
2488             + "  <label for='e3'> and here</label>\n"
2489             + "  <select id='e3'>e 3</select><br>\n"
2490             + "  <label id='l4' for='e4'> what about</label>\n"
2491             + "  <label> this<select id='e4'>e 4</select></label><br>\n"
2492             + "</body></html>";
2493 
2494         loadPageVerifyTitle2(html);
2495     }
2496 
2497     /**
2498      * @throws Exception if the test fails
2499      */
2500     @Test
2501     @Alerts({"1", "false", "true", "false", "false"})
2502     public void in() throws Exception {
2503         final String html = DOCTYPE_HTML
2504             + "<html>\n"
2505             + "<head>\n"
2506             + "<script>\n"
2507             + LOG_TITLE_FUNCTION
2508             + "  function doTest() {\n"
2509             + "    var options = document.form1.select1.options;\n"
2510             + "    log(options.length);\n"
2511             + "    log(-1 in options);\n"
2512             + "    log(0 in options);\n"
2513             + "    log(1 in options);\n"
2514             + "    log(42 in options);\n"
2515             + "  }\n"
2516             + "</script>\n"
2517             + "</head>\n2"
2518             + "<body onload='doTest()'>\n"
2519             + "  <form name='form1'>\n"
2520             + "    <select name='select1'>\n"
2521             + "      <option name='option1' value='value1'>One</option>\n"
2522             + "    </select>\n"
2523             + "  </form>\n"
2524             + "</body></html>";
2525 
2526         loadPageVerifyTitle2(html);
2527     }
2528 
2529     /**
2530      * @throws Exception if the test fails
2531      */
2532     @Test
2533     @Alerts({"undefined", "[object HTMLOptionElement]", "2"})
2534     public void addOptionByAssigningViaIndex() throws Exception {
2535         final String html = DOCTYPE_HTML
2536             + "<html>\n"
2537             + "<head>\n"
2538             + "  <script>\n"
2539             + LOG_TITLE_FUNCTION
2540             + "    function doTest() {\n"
2541             + "      var select = document.getElementById('select1');\n"
2542             + "      log(select[1]);\n"
2543             + "      select[1] = new Option('text','value');\n"
2544             + "      log(select[1]);\n"
2545             + "      log(select.options.length);\n"
2546             + "    }\n"
2547             + "  </script>\n"
2548             + "</head>\n"
2549             + "<body onload='doTest()'>\n"
2550             + "  <select id='select1'>\n"
2551             + "    <option name='option1' value='value1'>One</option>\n"
2552             + "  </select>\n"
2553             + "</body></html>";
2554 
2555         loadPageVerifyTitle2(html);
2556     }
2557 
2558     /**
2559      * @throws Exception if the test fails
2560      */
2561     @Test
2562     @Alerts({"undefined", "[object HTMLOptionElement]", "8"})
2563     public void addOptionByAssigningViaIndex2() throws Exception {
2564         final String html = DOCTYPE_HTML
2565             + "<html>\n"
2566             + "<head>\n"
2567             + "  <script>\n"
2568             + LOG_TITLE_FUNCTION
2569             + "    function doTest() {\n"
2570             + "      var select = document.getElementById('select1');\n"
2571             + "      log(select[7]);\n"
2572             + "      select[7] = new Option('text','value');\n"
2573             + "      log(select[7]);\n"
2574             + "      log(select.options.length);\n"
2575             + "    }\n"
2576             + "  </script>\n"
2577             + "</head>\n"
2578             + "<body onload='doTest()'>\n"
2579             + "  <select id='select1'>\n"
2580             + "    <option name='option1' value='value1'>One</option>\n"
2581             + "  </select>\n"
2582             + "</body></html>";
2583 
2584         loadPageVerifyTitle2(html);
2585     }
2586 
2587     /**
2588      * @throws Exception if the test fails
2589      */
2590     @Test
2591     @Alerts("[object HTMLFormElement]")
2592     public void form() throws Exception {
2593         final String html = DOCTYPE_HTML
2594             + "<html>\n"
2595             + "<body>\n"
2596             + "  <form>\n"
2597             + "    <select id='a'>\n"
2598             + "      <option name='option1' value='value1'>One</option>\n"
2599             + "    </select>\n"
2600             + "  </form>"
2601             + "  <script>\n"
2602             + LOG_TITLE_FUNCTION
2603             + "    log(document.getElementById('a').form);\n"
2604             + "  </script>"
2605             + "</body>"
2606             + "</html>";
2607 
2608         loadPageVerifyTitle2(html);
2609     }
2610 
2611     /**
2612      * @throws Exception if the test fails
2613      */
2614     @Test
2615     public void deselectFromMultiple() throws Exception {
2616         final String html = DOCTYPE_HTML
2617             + "<html><body>\n"
2618             + "<select id='s' multiple>\n"
2619             + "  <option selected value='one'>One</option>\n"
2620             + "  <option value='two'>Two</option>\n"
2621             + "  <option selected value='three'>Three</option>\n"
2622             + "</select>\n"
2623             + "</body></html>";
2624 
2625         final WebDriver driver = loadPage2(html);
2626         final WebElement multiSelect = driver.findElement(By.id("s"));
2627         final List<WebElement> options = multiSelect.findElements(By.tagName("option"));
2628 
2629         WebElement option = options.get(0);
2630         assertTrue(option.isSelected());
2631         option.click();
2632         assertFalse(option.isSelected());
2633         option.click();
2634         assertTrue(option.isSelected());
2635 
2636         option = options.get(2);
2637         assertTrue(option.isSelected());
2638     }
2639 
2640     /**
2641      * @throws Exception if the test fails
2642      */
2643     @Test
2644     public void optionClick() throws Exception {
2645         final String html = DOCTYPE_HTML
2646             + "<html><body>\n"
2647             + "<select id='s' multiple>\n"
2648             + "  <option selected value='one'>One</option>\n"
2649             + "  <option value='two'>Two</option>\n"
2650             + "  <option selected value='three'>Three</option>\n"
2651             + "</select>\n"
2652             + "</body></html>";
2653 
2654         final WebDriver driver = loadPage2(html);
2655         final WebElement multiSelect = driver.findElement(By.id("s"));
2656         final List<WebElement> options = multiSelect.findElements(By.tagName("option"));
2657 
2658         assertTrue(options.get(0).isSelected());
2659         assertFalse(options.get(1).isSelected());
2660         assertTrue(options.get(2).isSelected());
2661 
2662         options.get(0).click();
2663 
2664         assertFalse(options.get(0).isSelected());
2665         assertFalse(options.get(1).isSelected());
2666         assertTrue(options.get(2).isSelected());
2667     }
2668 
2669     /**
2670      * @throws Exception if the test fails
2671      */
2672     @Test
2673     // https://github.com/mozilla/geckodriver/issues/584
2674     public void optionClickActions() throws Exception {
2675         final String html = DOCTYPE_HTML
2676             + "<html><body>\n"
2677             + "<select id='s' multiple>\n"
2678             + "  <option selected value='one'>One</option>\n"
2679             + "  <option value='two'>Two</option>\n"
2680             + "  <option selected value='three'>Three</option>\n"
2681             + "</select>\n"
2682             + "</body></html>";
2683 
2684         final WebDriver driver = loadPage2(html);
2685         final WebElement multiSelect = driver.findElement(By.id("s"));
2686         final List<WebElement> options = multiSelect.findElements(By.tagName("option"));
2687 
2688         assertTrue(options.get(0).isSelected());
2689         assertFalse(options.get(1).isSelected());
2690         assertTrue(options.get(2).isSelected());
2691 
2692         new Actions(driver).click(options.get(0)).perform();
2693 
2694         assertTrue(options.get(0).isSelected());
2695         assertFalse(options.get(1).isSelected());
2696         assertFalse(options.get(2).isSelected());
2697     }
2698 
2699     /**
2700      * @throws Exception if an error occurs
2701      */
2702     @Test
2703     @Alerts({"[object HTMLOptionElement]", "[object HTMLOptionElement]", "[object HTMLOptionElement]"})
2704     public void optionsForOf() throws Exception {
2705         final String html = DOCTYPE_HTML
2706             + "<html>\n"
2707             + "<head>\n"
2708             + "<script>\n"
2709             + LOG_TITLE_FUNCTION
2710             + "  function test() {\n"
2711             + "    var s = document.getElementById('s');\n"
2712             + "    for (var opt of s) {\n"
2713             + "      log(opt);\n"
2714             + "    }\n"
2715             + "  }\n"
2716             + "</script>\n"
2717             + "</head>\n"
2718             + "<body onload='test()'>\n"
2719             + "<select id='s' multiple>\n"
2720             + "  <option selected value='one'>One</option>\n"
2721             + "  <option value='two'>Two</option>\n"
2722             + "  <option selected value='three'>Three</option>\n"
2723             + "</select>\n"
2724             + "</body>\n"
2725             + "</html>";
2726 
2727         loadPageVerifyTitle2(html);
2728     }
2729 
2730     /**
2731      * @throws Exception if an error occurs
2732      */
2733     @Test
2734     @Alerts(DEFAULT = {"true", "false", "true", "false", "true"},
2735             FF = {"true", "false", "true", "true", "true"},
2736             FF_ESR = {"true", "false", "true", "true", "true"})
2737     public void willValidate() throws Exception {
2738         final String html = DOCTYPE_HTML
2739                 + "<html><head>\n"
2740                 + "  <script>\n"
2741                 + LOG_TITLE_FUNCTION
2742                 + "    function test() {\n"
2743                 + "      log(document.getElementById('i1').willValidate);\n"
2744                 + "      log(document.getElementById('i2').willValidate);\n"
2745                 + "      log(document.getElementById('i3').willValidate);\n"
2746                 + "      log(document.getElementById('i4').willValidate);\n"
2747                 + "      log(document.getElementById('i5').willValidate);\n"
2748                 + "    }\n"
2749                 + "  </script>\n"
2750                 + "</head>\n"
2751                 + "<body onload='test()'>\n"
2752                 + "  <form>\n"
2753                 + "    <select id='i1'>button</select>"
2754                 + "    <select id='i2' disabled></select>"
2755                 + "    <select id='i3' hidden></select>"
2756                 + "    <select id='i4' readonly></select>"
2757                 + "    <select id='i5' style='display: none'></select>"
2758                 + "  </form>\n"
2759                 + "</body></html>";
2760 
2761         loadPageVerifyTitle2(html);
2762     }
2763 }