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.html;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  import org.openqa.selenium.By;
23  import org.openqa.selenium.WebDriver;
24  import org.openqa.selenium.htmlunit.HtmlUnitDriver;
25  
26  /**
27   * Tests for {@link HtmlLabel}.
28   *
29   * @author Marc Guillemot
30   * @author Ahmed Ashour
31   * @author Frank Danek
32   * @author Ronald Brill
33   */
34  @RunWith(BrowserRunner.class)
35  public class HtmlLabelTest extends WebDriverTestCase {
36  
37      /**
38       * @throws Exception if the test fails
39       */
40      @Test
41      @Alerts("[object HTMLLabelElement]")
42      public void simpleScriptable() throws Exception {
43          final String html = DOCTYPE_HTML
44              + "<html><head>\n"
45              + "<script>\n"
46              + LOG_TITLE_FUNCTION
47              + "  function test() {\n"
48              + "    log(document.getElementById('myId'));\n"
49              + "  }\n"
50              + "</script>\n"
51              + "</head><body onload='test()'>\n"
52              + "<label id='myId'>Item</label>\n"
53              + "</body></html>";
54  
55          final WebDriver driver = loadPageVerifyTitle2(html);
56          if (driver instanceof HtmlUnitDriver) {
57              final HtmlPage page = (HtmlPage) getEnclosedPage();
58              assertTrue(HtmlLabel.class.isInstance(page.getHtmlElementById("myId")));
59          }
60      }
61  
62      /**
63       * @throws Exception if the test fails
64       */
65      @Test
66      public void getLabeledElementNone() throws Exception {
67          final String html = DOCTYPE_HTML
68              + "<html>\n"
69              + "<body>\n"
70              + "  <label id='label1'>Item</label>\n"
71              + "  <input type='text' id='text1'>\n"
72              + "</body></html>";
73  
74          final WebDriver driver = loadPage2(html);
75          if (driver instanceof HtmlUnitDriver) {
76              final HtmlPage page = (HtmlPage) getEnclosedPage();
77              final HtmlLabel label = page.getHtmlElementById("label1");
78              assertNull(label.getLabeledElement());
79          }
80      }
81  
82      /**
83       * @throws Exception if the test fails
84       */
85      @Test
86      public void getLabeledElementForEmpty() throws Exception {
87          final String html = DOCTYPE_HTML
88              + "<html>\n"
89              + "<body>\n"
90              + "  <label id='label1' for=''>Item</label>\n"
91              + "  <input type='text' id='text1'>\n"
92              + "</body></html>";
93  
94          final WebDriver driver = loadPage2(html);
95          if (driver instanceof HtmlUnitDriver) {
96              final HtmlPage page = (HtmlPage) getEnclosedPage();
97              final HtmlLabel label = page.getHtmlElementById("label1");
98              assertNull(label.getLabeledElement());
99          }
100     }
101 
102     /**
103      * @throws Exception if the test fails
104      */
105     @Test
106     public void getLabeledElementForUnknown() throws Exception {
107         final String html = DOCTYPE_HTML
108             + "<html>\n"
109             + "<body>\n"
110             + "  <label id='label1' for='unknown'>Item</label>\n"
111             + "  <input type='text' id='text1'>\n"
112             + "</body></html>";
113 
114         final WebDriver driver = loadPage2(html);
115         if (driver instanceof HtmlUnitDriver) {
116             final HtmlPage page = (HtmlPage) getEnclosedPage();
117             final HtmlLabel label = page.getHtmlElementById("label1");
118             assertNull(label.getLabeledElement());
119         }
120     }
121 
122     /**
123      * @throws Exception if the test fails
124      */
125     @Test
126     public void getLabeledElementForNotLabelable() throws Exception {
127         final String html = DOCTYPE_HTML
128             + "<html>\n"
129             + "<body>\n"
130             + "  <label id='label1' for='div1'>Item</label>\n"
131             + "  <div id='div1'></div>\n"
132             + "</body></html>";
133 
134         final WebDriver driver = loadPage2(html);
135         if (driver instanceof HtmlUnitDriver) {
136             final HtmlPage page = (HtmlPage) getEnclosedPage();
137             final HtmlLabel label = page.getHtmlElementById("label1");
138             assertNull(label.getLabeledElement());
139         }
140     }
141 
142     /**
143      * @throws Exception if the test fails
144      */
145     @Test
146     public void getLabeledElementForButton() throws Exception {
147         final String html = DOCTYPE_HTML
148             + "<html>\n"
149             + "<body>\n"
150             + "  <label id='label1' for='button1'>Item</label>\n"
151             + "  <button id='button1'></button>\n"
152             + "</body></html>";
153 
154         final WebDriver driver = loadPage2(html);
155         if (driver instanceof HtmlUnitDriver) {
156             final HtmlPage page = (HtmlPage) getEnclosedPage();
157             final HtmlLabel label = page.getHtmlElementById("label1");
158             assertEquals("button1", label.getLabeledElement().getId());
159         }
160     }
161 
162     /**
163      * @throws Exception if the test fails
164      */
165     @Test
166     public void getLabeledElementForInput() throws Exception {
167         final String html = DOCTYPE_HTML
168             + "<html>\n"
169             + "<body>\n"
170             + "  <label id='label1' for='text1'>Item</label>\n"
171             + "  <input type='text' id='text1'>\n"
172             + "</body></html>";
173 
174         final WebDriver driver = loadPage2(html);
175         if (driver instanceof HtmlUnitDriver) {
176             final HtmlPage page = (HtmlPage) getEnclosedPage();
177             final HtmlLabel label = page.getHtmlElementById("label1");
178             assertEquals("text1", label.getLabeledElement().getId());
179         }
180     }
181 
182     /**
183      * @throws Exception if the test fails
184      */
185     @Test
186     public void getLabeledElementForInputHidden() throws Exception {
187         final String html = DOCTYPE_HTML
188             + "<html>\n"
189             + "<body>\n"
190             + "  <label id='label1' for='hidden1'>Item</label>\n"
191             + "  <input type='hidden' id='hidden1'>\n"
192             + "</body></html>";
193 
194         final WebDriver driver = loadPage2(html);
195         if (driver instanceof HtmlUnitDriver) {
196             final HtmlPage page = (HtmlPage) getEnclosedPage();
197             final HtmlLabel label = page.getHtmlElementById("label1");
198             assertNull(label.getLabeledElement());
199         }
200     }
201 
202     /**
203      * @throws Exception if the test fails
204      */
205     @Test
206     @Alerts("meter1")
207     public void getLabeledElementForMeter() throws Exception {
208         final String html = DOCTYPE_HTML
209             + "<html>\n"
210             + "<body>\n"
211             + "  <label id='label1' for='meter1'>Item</label>\n"
212             + "  <meter id='meter1'></meter>\n"
213             + "</body></html>";
214 
215         final WebDriver driver = loadPage2(html);
216         if (driver instanceof HtmlUnitDriver) {
217             final HtmlPage page = (HtmlPage) getEnclosedPage();
218             final HtmlLabel label = page.getHtmlElementById("label1");
219 
220             final String txt;
221             if (null == label.getLabeledElement()) {
222                 txt = "null";
223             }
224             else {
225                 txt = label.getLabeledElement().getId();
226             }
227             assertEquals(getExpectedAlerts()[0], txt);
228         }
229     }
230 
231     /**
232      * @throws Exception if the test fails
233      */
234     @Test
235     @Alerts("output1")
236     public void getLabeledElementForOutput() throws Exception {
237         final String html = DOCTYPE_HTML
238             + "<html>\n"
239             + "<body>\n"
240             + "  <label id='label1' for='output1'>Item</label>\n"
241             + "  <output id='output1'></output>\n"
242             + "</body></html>";
243 
244         final WebDriver driver = loadPage2(html);
245         if (driver instanceof HtmlUnitDriver) {
246             final HtmlPage page = (HtmlPage) getEnclosedPage();
247             final HtmlLabel label = page.getHtmlElementById("label1");
248 
249             final String txt;
250             if (null == label.getLabeledElement()) {
251                 txt = "null";
252             }
253             else {
254                 txt = label.getLabeledElement().getId();
255             }
256             assertEquals(getExpectedAlerts()[0], txt);
257         }
258     }
259 
260     /**
261      * @throws Exception if the test fails
262      */
263     @Test
264     public void getLabeledElementForProgress() throws Exception {
265         final String html = DOCTYPE_HTML
266             + "<html>\n"
267             + "<body>\n"
268             + "  <label id='label1' for='progress1'>Item</label>\n"
269             + "  <progress id='progress1'></progress>\n"
270             + "</body></html>";
271 
272         final WebDriver driver = loadPage2(html);
273         if (driver instanceof HtmlUnitDriver) {
274             final HtmlPage page = (HtmlPage) getEnclosedPage();
275             final HtmlLabel label = page.getHtmlElementById("label1");
276             assertEquals("progress1", label.getLabeledElement().getId());
277         }
278     }
279 
280     /**
281      * @throws Exception if the test fails
282      */
283     @Test
284     public void getLabeledElementForSelect() throws Exception {
285         final String html = DOCTYPE_HTML
286             + "<html>\n"
287             + "<body>\n"
288             + "  <label id='label1' for='select1'>Item</label>\n"
289             + "  <select id='select1'><option>Option</option></select>\n"
290             + "</body></html>";
291 
292         final WebDriver driver = loadPage2(html);
293         if (driver instanceof HtmlUnitDriver) {
294             final HtmlPage page = (HtmlPage) getEnclosedPage();
295             final HtmlLabel label = page.getHtmlElementById("label1");
296             assertEquals("select1", label.getLabeledElement().getId());
297         }
298     }
299 
300     /**
301      * @throws Exception if the test fails
302      */
303     @Test
304     public void getLabeledElementForTextArea() throws Exception {
305         final String html = DOCTYPE_HTML
306             + "<html>\n"
307             + "<body>\n"
308             + "  <label id='label1' for='text1'>Item</label>\n"
309             + "  <textarea id='text1'></textarea>\n"
310             + "</body></html>";
311 
312         final WebDriver driver = loadPage2(html);
313         if (driver instanceof HtmlUnitDriver) {
314             final HtmlPage page = (HtmlPage) getEnclosedPage();
315             final HtmlLabel label = page.getHtmlElementById("label1");
316             assertEquals("text1", label.getLabeledElement().getId());
317         }
318     }
319 
320     /**
321      * @throws Exception if the test fails
322      */
323     @Test
324     public void getLabeledElementNestedNotLabelable() throws Exception {
325         final String html = DOCTYPE_HTML
326             + "<html>\n"
327             + "<body>\n"
328             + "  <label id='label1'>Item\n"
329             + "    <div id='div1'></div>\n"
330             + "  </label>\n"
331             + "</body></html>";
332 
333         final WebDriver driver = loadPage2(html);
334         if (driver instanceof HtmlUnitDriver) {
335             final HtmlPage page = (HtmlPage) getEnclosedPage();
336             final HtmlLabel label = page.getHtmlElementById("label1");
337             assertNull(label.getLabeledElement());
338         }
339     }
340 
341     /**
342      * @throws Exception if the test fails
343      */
344     @Test
345     public void getLabeledElementNestedButton() throws Exception {
346         final String html = DOCTYPE_HTML
347             + "<html>\n"
348             + "<body>\n"
349             + "  <label id='label1'>Item\n"
350             + "    <button id='button1'></button>\n"
351             + "    <button id='button2'></button>\n"
352             + "  </label>\n"
353             + "</body></html>";
354 
355         final WebDriver driver = loadPage2(html);
356         if (driver instanceof HtmlUnitDriver) {
357             final HtmlPage page = (HtmlPage) getEnclosedPage();
358             final HtmlLabel label = page.getHtmlElementById("label1");
359             assertEquals("button1", label.getLabeledElement().getId());
360         }
361     }
362 
363     /**
364      * @throws Exception if the test fails
365      */
366     @Test
367     public void getLabeledElementNestedInput() throws Exception {
368         final String html = DOCTYPE_HTML
369             + "<html>\n"
370             + "<body>\n"
371             + "  <label id='label1'>Item\n"
372             + "    <input type='text' id='text1'>\n"
373             + "    <input type='text' id='text2'>\n"
374             + "  </label>\n"
375             + "</body></html>";
376 
377         final WebDriver driver = loadPage2(html);
378         if (driver instanceof HtmlUnitDriver) {
379             final HtmlPage page = (HtmlPage) getEnclosedPage();
380             final HtmlLabel label = page.getHtmlElementById("label1");
381             assertEquals("text1", label.getLabeledElement().getId());
382         }
383     }
384 
385     /**
386      * @throws Exception if the test fails
387      */
388     @Test
389     public void getLabeledElementNestedInputHidden() throws Exception {
390         final String html = DOCTYPE_HTML
391             + "<html>\n"
392             + "<body>\n"
393             + "  <label id='label1'>Item\n"
394             + "    <input type='hidden' id='hidden1'>\n"
395             + "    <input type='hidden' id='hidden2'>\n"
396             + "  </label>\n"
397             + "</body></html>";
398 
399         final WebDriver driver = loadPage2(html);
400         if (driver instanceof HtmlUnitDriver) {
401             final HtmlPage page = (HtmlPage) getEnclosedPage();
402             final HtmlLabel label = page.getHtmlElementById("label1");
403             assertNull(label.getLabeledElement());
404         }
405     }
406 
407     /**
408      * @throws Exception if the test fails
409      */
410     @Test
411     @Alerts("meter1")
412     public void getLabeledElementNestedMeter() throws Exception {
413         final String html = DOCTYPE_HTML
414             + "<html>\n"
415             + "<body>\n"
416             + "  <label id='label1'>Item\n"
417             + "    <meter id='meter1'></meter>\n"
418             + "    <meter id='meter2'></meter>\n"
419             + "  </label>\n"
420             + "</body></html>";
421 
422         final WebDriver driver = loadPage2(html);
423         if (driver instanceof HtmlUnitDriver) {
424             final HtmlPage page = (HtmlPage) getEnclosedPage();
425             final HtmlLabel label = page.getHtmlElementById("label1");
426 
427             final String txt;
428             if (null == label.getLabeledElement()) {
429                 txt = "null";
430             }
431             else {
432                 txt = label.getLabeledElement().getId();
433             }
434             assertEquals(getExpectedAlerts()[0], txt);
435         }
436     }
437 
438     /**
439      * @throws Exception if the test fails
440      */
441     @Test
442     @Alerts("output1")
443     public void getLabeledElementNestedOutput() throws Exception {
444         final String html = DOCTYPE_HTML
445             + "<html>\n"
446             + "<body>\n"
447             + "  <label id='label1'>Item\n"
448             + "    <output id='output1'></output>\n"
449             + "    <output id='output2'></output>\n"
450             + "  </label>\n"
451             + "</body></html>";
452 
453         final WebDriver driver = loadPage2(html);
454         if (driver instanceof HtmlUnitDriver) {
455             final HtmlPage page = (HtmlPage) getEnclosedPage();
456             final HtmlLabel label = page.getHtmlElementById("label1");
457 
458             final String txt;
459             if (null == label.getLabeledElement()) {
460                 txt = "null";
461             }
462             else {
463                 txt = label.getLabeledElement().getId();
464             }
465             assertEquals(getExpectedAlerts()[0], txt);
466         }
467     }
468 
469     /**
470      * @throws Exception if the test fails
471      */
472     @Test
473     public void getLabeledElementNestedProgress() throws Exception {
474         final String html = DOCTYPE_HTML
475             + "<html>\n"
476             + "<body>\n"
477             + "  <label id='label1'>Item\n"
478             + "    <progress id='progress1'></progress>\n"
479             + "    <progress id='progress2'></progress>\n"
480             + "  </label>\n"
481             + "</body></html>";
482 
483         final WebDriver driver = loadPage2(html);
484         if (driver instanceof HtmlUnitDriver) {
485             final HtmlPage page = (HtmlPage) getEnclosedPage();
486             final HtmlLabel label = page.getHtmlElementById("label1");
487             assertEquals("progress1", label.getLabeledElement().getId());
488         }
489     }
490 
491     /**
492      * @throws Exception if the test fails
493      */
494     @Test
495     public void getLabeledElementNestedSelect() throws Exception {
496         final String html = DOCTYPE_HTML
497             + "<html>\n"
498             + "<body>\n"
499             + "  <label id='label1'>Item\n"
500             + "    <select id='select1'><option>Option</option></select>\n"
501             + "    <select id='select2'><option>Option</option></select>\n"
502             + "  </label>\n"
503             + "</body></html>";
504 
505         final WebDriver driver = loadPage2(html);
506         if (driver instanceof HtmlUnitDriver) {
507             final HtmlPage page = (HtmlPage) getEnclosedPage();
508             final HtmlLabel label = page.getHtmlElementById("label1");
509             assertEquals("select1", label.getLabeledElement().getId());
510         }
511     }
512 
513     /**
514      * @throws Exception if the test fails
515      */
516     @Test
517     public void getLabeledElementNestedTextArea() throws Exception {
518         final String html = DOCTYPE_HTML
519             + "<html>\n"
520             + "<body>\n"
521             + "  <label id='label1'>Item\n"
522             + "    <textarea id='text1'></textarea>\n"
523             + "    <textarea id='text2'></textarea>\n"
524             + "  </label>\n"
525             + "</body></html>";
526 
527         final WebDriver driver = loadPage2(html);
528         if (driver instanceof HtmlUnitDriver) {
529             final HtmlPage page = (HtmlPage) getEnclosedPage();
530             final HtmlLabel label = page.getHtmlElementById("label1");
531             assertEquals("text1", label.getLabeledElement().getId());
532         }
533     }
534 
535     /**
536      * @throws Exception if the test fails
537      */
538     @Test
539     public void getLabeledElementForVersusNested() throws Exception {
540         final String html = DOCTYPE_HTML
541             + "<html>\n"
542             + "<body>\n"
543             + "  <label id='label1' for='text2'>Item\n"
544             + "    <input type='text' id='text1'>\n"
545             + "  </label>\n"
546             + "  <input type='text' id='text2'>\n"
547             + "</body></html>";
548 
549         final WebDriver driver = loadPage2(html);
550         if (driver instanceof HtmlUnitDriver) {
551             final HtmlPage page = (HtmlPage) getEnclosedPage();
552             final HtmlLabel label = page.getHtmlElementById("label1");
553             assertEquals("text2", label.getLabeledElement().getId());
554         }
555     }
556 
557     /**
558      * @throws Exception if the test fails
559      */
560     @Test
561     public void getLabeledElementForUnknownVersusNested() throws Exception {
562         final String html = DOCTYPE_HTML
563             + "<html>\n"
564             + "<body>\n"
565             + "  <label id='label1' for='unknown'>Item\n"
566             + "    <input type='text' id='text1'>\n"
567             + "  </label>\n"
568             + "  <input type='text' id='text2'>\n"
569             + "</body></html>";
570 
571         final WebDriver driver = loadPage2(html);
572         if (driver instanceof HtmlUnitDriver) {
573             final HtmlPage page = (HtmlPage) getEnclosedPage();
574             final HtmlLabel label = page.getHtmlElementById("label1");
575             assertNull(label.getLabeledElement());
576         }
577     }
578 
579     /**
580      * @throws Exception if the test fails
581      */
582     @Test
583     public void getLabeledElementForNotLabelableVersusNested() throws Exception {
584         final String html = DOCTYPE_HTML
585             + "<html>\n"
586             + "<body>\n"
587             + "  <label id='label1' for='div1'>Item\n"
588             + "    <input type='text' id='text1'>\n"
589             + "  </label>\n"
590             + "  <div id='div1'></div>\n"
591             + "</body></html>";
592 
593         final WebDriver driver = loadPage2(html);
594         if (driver instanceof HtmlUnitDriver) {
595             final HtmlPage page = (HtmlPage) getEnclosedPage();
596             final HtmlLabel label = page.getHtmlElementById("label1");
597             assertNull(label.getLabeledElement());
598         }
599     }
600 
601     /**
602      * @throws Exception if an error occurs
603      */
604     @Test
605     @Alerts("labelclick")
606     public void clickNone() throws Exception {
607         final String html =
608               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me</label>\n"
609             + "  <input type='text' id='text1' onclick='log(\"textclick\")' onfocus='log(\"textfocus\")'>\n";
610         final WebDriver driver = loadPage2(generatePage(html));
611         driver.findElement(By.id("label1")).click();
612         verifyTitle2(driver, getExpectedAlerts());
613         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
614     }
615 
616     /**
617      * @throws Exception if an error occurs
618      */
619     @Test
620     @Alerts({"labelclick:label1", "parentclick:label1"})
621     public void clickNoneEventBubbling() throws Exception {
622         final String html =
623               "  <div onclick='log(\"parentclick:\" + event.target.id)' "
624                       + "onfocus='log(\"parentfocus:\" + event.target.id)'>\n"
625               + "    <label id='label1' onclick='log(\"labelclick:\" + event.target.id)' "
626                       + "onfocus='log(\"labelfocus:\" + event.target.id)'>Click me</label>\n"
627               + "    <input type='text' id='text1' onclick='log(\"textclick:\" + event.target.id)' "
628                       + "onfocus='log(\"textfocus:\" + event.target.id)'>\n"
629               + "  </div>\n";
630         final WebDriver driver = loadPage2(generatePage(html));
631         driver.findElement(By.id("label1")).click();
632         verifyTitle2(driver, getExpectedAlerts());
633         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
634     }
635 
636     /**
637      * @throws Exception if an error occurs
638      */
639     @Test
640     @Alerts("labelclick")
641     public void clickForEmpty() throws Exception {
642         final String html =
643               "  <label id='label1' for='' onclick='log(\"labelclick\")' "
644                       + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
645               + "  <input type='text' id='text1' onclick='log(\"textclick\")' onfocus='log(\"textfocus\")'>\n";
646         final WebDriver driver = loadPage2(generatePage(html));
647         driver.findElement(By.id("label1")).click();
648         verifyTitle2(driver, getExpectedAlerts());
649         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
650     }
651 
652     /**
653      * @throws Exception if an error occurs
654      */
655     @Test
656     @Alerts("labelclick")
657     public void clickForUnknown() throws Exception {
658         final String html =
659               "  <label id='label1' for='unknown' onclick='log(\"labelclick\")' "
660                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
661               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
662                           + "onfocus='log(\"textfocus\")'>\n";
663         final WebDriver driver = loadPage2(generatePage(html));
664         driver.findElement(By.id("label1")).click();
665         verifyTitle2(driver, getExpectedAlerts());
666         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
667     }
668 
669     /**
670      * @throws Exception if an error occurs
671      */
672     @Test
673     @Alerts("labelclick")
674     public void clickForNotLabelable() throws Exception {
675         final String html =
676               "  <label id='label1' for='div1' onclick='log(\"labelclick\")' "
677                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
678               + "  <div id='div1' onclick='log(\"divclick\")' "
679                           + "onfocus='log(\"divfocus\")'></div>\n";
680         final WebDriver driver = loadPage2(generatePage(html));
681         driver.findElement(By.id("label1")).click();
682         verifyTitle2(driver, getExpectedAlerts());
683         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
684     }
685 
686     /**
687      * @throws Exception if an error occurs
688      */
689     @Test
690     @Alerts({"labelclick", "textfocus", "textclick"})
691     public void clickForInput() throws Exception {
692         final String html =
693               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
694                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
695               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
696                           + "onfocus='log(\"textfocus\")'>\n";
697         final WebDriver driver = loadPage2(generatePage(html));
698         driver.findElement(By.id("label1")).click();
699         verifyTitle2(driver, getExpectedAlerts());
700         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
701     }
702 
703     /**
704      * @throws Exception if an error occurs
705      */
706     @Test
707     @Alerts({"labelclick", "selectfocus", "selectclick"})
708     public void clickForSelect() throws Exception {
709         final String html =
710               "  <label id='label1' for='select1' onclick='log(\"labelclick\")' "
711                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
712               + "  <select id='select1' onclick='log(\"selectclick\")' "
713                           + "onfocus='log(\"selectfocus\")'><option>Option</option></select>\n";
714         final WebDriver driver = loadPage2(generatePage(html));
715         driver.findElement(By.id("label1")).click();
716         verifyTitle2(driver, getExpectedAlerts());
717         assertEquals(driver.findElement(By.id("select1")), driver.switchTo().activeElement());
718     }
719 
720     /**
721      * @throws Exception if an error occurs
722      */
723     @Test
724     @Alerts({"labelclick", "textfocus", "textclick"})
725     public void clickForTextArea() throws Exception {
726         final String html =
727               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
728                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
729               + "  <textarea id='text1' onclick='log(\"textclick\")' "
730                           + "onfocus='log(\"textfocus\")'></textarea>\n";
731         final WebDriver driver = loadPage2(generatePage(html));
732         driver.findElement(By.id("label1")).click();
733         verifyTitle2(driver, getExpectedAlerts());
734         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
735     }
736 
737     /**
738      * @throws Exception if an error occurs
739      */
740     @Test
741     @Alerts("labelclick")
742     public void clickForDisabled() throws Exception {
743         final String html =
744               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
745                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
746               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
747                           + "onfocus='log(\"textfocus\")' disabled>\n";
748         final WebDriver driver = loadPage2(generatePage(html));
749         driver.findElement(By.id("label1")).click();
750         verifyTitle2(driver, getExpectedAlerts());
751         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
752     }
753 
754     /**
755      * @throws Exception if an error occurs
756      */
757     @Test
758     @Alerts({"labelclick", "textclick"})
759     public void clickForNotDisplayed() throws Exception {
760         final String html =
761               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
762                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
763               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
764                           + "onfocus='log(\"textfocus\")' style='display: none;'>\n";
765         final WebDriver driver = loadPage2(generatePage(html));
766         driver.findElement(By.id("label1")).click();
767         verifyTitle2(driver, getExpectedAlerts());
768         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
769     }
770 
771     /**
772      * @throws Exception if an error occurs
773      */
774     @Test
775     @Alerts({"labelclick", "textclick"})
776     public void clickForNotVisible() throws Exception {
777         final String html =
778               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
779                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
780               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
781                           + "onfocus='log(\"textfocus\")' style='visibility: hidden;'>\n";
782         final WebDriver driver = loadPage2(generatePage(html));
783         driver.findElement(By.id("label1")).click();
784         verifyTitle2(driver, getExpectedAlerts());
785         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
786     }
787 
788     /**
789      * @throws Exception if an error occurs
790      */
791     @Test
792     @Alerts({"labelclick", "textclick"})
793     public void clickForHidden() throws Exception {
794         final String html =
795               "  <label id='label1' for='text1' onclick='log(\"labelclick\")' "
796                           + "onfocus='log(\"labelfocus\")'>Click me</label>\n"
797               + "  <input type='text' id='text1' onclick='log(\"textclick\")' "
798                           + "onfocus='log(\"textfocus\")' hidden>\n";
799         final WebDriver driver = loadPage2(generatePage(html));
800         driver.findElement(By.id("label1")).click();
801         verifyTitle2(driver, getExpectedAlerts());
802         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
803     }
804 
805     /**
806      * @throws Exception if an error occurs
807      */
808     @Test
809     @Alerts({"labelclick:label1", "parentclick:label1", "textfocus:text1",
810              "textclick:text1", "parentclick:text1"})
811     public void clickForEventBubbling() throws Exception {
812         final String html =
813               "  <div onclick='log(\"parentclick:\" + event.target.id)' "
814                           + "onfocus='log(\"parentfocus:\" + event.target.id)'>\n"
815               + "    <label id='label1' for='text1' onclick='log(\"labelclick:\" + event.target.id)' "
816                           + "onfocus='log(\"labelfocus:\" + event.target.id)'>Click me</label>\n"
817               + "    <input type='text' id='text1' onclick='log(\"textclick:\" + event.target.id)' "
818                           + "onfocus='log(\"textfocus:\" + event.target.id)'>\n"
819               + "  </div>\n";
820         final WebDriver driver = loadPage2(generatePage(html));
821         driver.findElement(By.id("label1")).click();
822         verifyTitle2(driver, getExpectedAlerts());
823         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
824     }
825 
826     /**
827      * @throws Exception if an error occurs
828      */
829     @Test
830     @Alerts("labelclick")
831     public void clickNestedNotLabelable() throws Exception {
832         final String html =
833               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
834             // we have to add some extra text to make Selenium click the label and not the nested element
835             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
836             + "    <div id='div1' onclick='log(\"divclick\")' onfocus='log(\"divfocus\")'></div>\n"
837             + "  </label>\n";
838         final WebDriver driver = loadPage2(generatePage(html));
839         driver.findElement(By.id("label1")).click();
840         verifyTitle2(driver, getExpectedAlerts());
841         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
842     }
843 
844     /**
845      * @throws Exception if an error occurs
846      */
847     @Test
848     @Alerts({"labelclick", "text1focus", "text1click", "labelclick"})
849     public void clickNestedInput() throws Exception {
850         final String html =
851               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
852             // we have to add some extra text to make Selenium click the label and not the nested element
853             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
854             + "    <input type='text' id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")'>\n"
855             + "    <input type='text' id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'>\n"
856             + "  </label>\n";
857         final WebDriver driver = loadPage2(generatePage(html));
858         driver.findElement(By.id("label1")).click();
859         verifyTitle2(driver, getExpectedAlerts());
860         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
861     }
862 
863     /**
864      * @throws Exception if an error occurs
865      */
866     @Test
867     @Alerts({"labelclick", "select1focus", "select1click", "labelclick"})
868     public void clickNestedSelect() throws Exception {
869         final String html =
870               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
871               // we have to add some extra text to make Selenium click the label and not the nested element
872               + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
873               + "    <select id='select1' onclick='log(\"select1click\")' "
874                           + "onfocus='log(\"select1focus\")'><option>Option</option></select>\n"
875               + "    <select id='select2' onclick='log(\"select2click\")' "
876                           + "onfocus='log(\"select2focus\")'><option>Option</option></select>\n"
877               + "  </label>\n";
878         final WebDriver driver = loadPage2(generatePage(html));
879         driver.findElement(By.id("label1")).click();
880         verifyTitle2(driver, getExpectedAlerts());
881         assertEquals(driver.findElement(By.id("select1")), driver.switchTo().activeElement());
882     }
883 
884     /**
885      * @throws Exception if an error occurs
886      */
887     @Test
888     @Alerts({"labelclick", "text1focus", "text1click", "labelclick"})
889     public void clickNestedTextArea() throws Exception {
890         final String html =
891               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
892             // we have to add some extra text to make Selenium click the label and not the nested element
893             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
894             + "    <textarea id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")'></textarea>\n"
895             + "    <textarea id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'></textarea>\n"
896             + "  </label>\n";
897         final WebDriver driver = loadPage2(generatePage(html));
898         driver.findElement(By.id("label1")).click();
899         verifyTitle2(driver, getExpectedAlerts());
900         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
901     }
902 
903     /**
904      * @throws Exception if an error occurs
905      */
906     @Test
907     @Alerts("labelclick")
908     public void clickNestedDisabled() throws Exception {
909         final String html =
910               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
911             // we have to add some extra text to make Selenium click the label and not the nested element
912             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
913             + "    <input type='text' id='text1' onclick='log(\"text1click\")' "
914                         + "onfocus='log(\"text1focus\")' disabled>\n"
915             + "    <input type='text' id='text2' onclick='log(\"text2click\")' "
916                         + "onfocus='log(\"text2focus\")'>\n"
917             + "  </label>\n";
918         final WebDriver driver = loadPage2(generatePage(html));
919         driver.findElement(By.id("label1")).click();
920         verifyTitle2(driver, getExpectedAlerts());
921         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
922     }
923 
924     /**
925      * @throws Exception if an error occurs
926      */
927     @Test
928     @Alerts({"labelclick", "text1click", "labelclick"})
929     public void clickNestedNotDisplayed() throws Exception {
930         final String html =
931               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
932               // we have to add some extra text to make Selenium click the label and not the nested element
933               + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
934               + "    <input type='text' id='text1' onclick='log(\"text1click\")' "
935                           + "onfocus='log(\"text1focus\")' style='display: none;'>\n"
936               + "    <input type='text' id='text2' onclick='log(\"text2click\")' "
937                           + "onfocus='log(\"text2focus\")'>\n"
938               + "  </label>\n";
939         final WebDriver driver = loadPage2(generatePage(html));
940         driver.findElement(By.id("label1")).click();
941         verifyTitle2(driver, getExpectedAlerts());
942         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
943     }
944 
945     /**
946      * @throws Exception if an error occurs
947      */
948     @Test
949     @Alerts({"labelclick", "text1click", "labelclick"})
950     public void clickNestedNotVisible() throws Exception {
951         final String html =
952               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
953             // we have to add some extra text to make Selenium click the label and not the nested element
954             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
955             + "    <input type='text' id='text1' onclick='log(\"text1click\")' "
956                         + "onfocus='log(\"text1focus\")' style='visibility: hidden;'>\n"
957             + "    <input type='text' id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'>\n"
958             + "  </label>\n";
959         final WebDriver driver = loadPage2(generatePage(html));
960         driver.findElement(By.id("label1")).click();
961         verifyTitle2(driver, getExpectedAlerts());
962         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
963     }
964 
965     /**
966      * @throws Exception if an error occurs
967      */
968     @Test
969     @Alerts({"labelclick", "text1click", "labelclick"})
970     public void clickNestedHidden() throws Exception {
971         final String html =
972               "  <label id='label1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
973             // we have to add some extra text to make Selenium click the label and not the nested element
974             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
975             + "    <input type='text' id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")' hidden>\n"
976             + "    <input type='text' id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'>\n"
977             + "  </label>\n";
978         final WebDriver driver = loadPage2(generatePage(html));
979         driver.findElement(By.id("label1")).click();
980         verifyTitle2(driver, getExpectedAlerts());
981         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
982     }
983 
984     /**
985      * @throws Exception if an error occurs
986      */
987     @Test
988     @Alerts({"labelclick:label1", "parentclick:label1", "text1focus:text1",
989              "text1click:text1", "labelclick:text1", "parentclick:text1"})
990     public void clickNestedEventBubbling() throws Exception {
991         final String html =
992               "  <div onclick='log(\"parentclick:\" + event.target.id)' "
993                       + "onfocus='log(\"parentfocus:\" + event.target.id)'>\n"
994               + "    <label id='label1' onclick='log(\"labelclick:\" + event.target.id)' "
995                           + "onfocus='log(\"labelfocus:\" + event.target.id)'>Click me"
996               // we have to add some extra text to make Selenium click the label and not the nested element
997               + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
998               + "      <input type='text' id='text1' onclick='log(\"text1click:\" + event.target.id)' "
999                           + "onfocus='log(\"text1focus:\" + event.target.id)'>\n"
1000               + "      <input type='text' id='text2' onclick='log(\"text2click:\" + event.target.id)' "
1001                           + "onfocus='log(\"text2focus:\" + event.target.id)'>\n"
1002               + "    </label>\n"
1003               + "  </div>\n";
1004         final WebDriver driver = loadPage2(generatePage(html));
1005         driver.findElement(By.id("label1")).click();
1006         verifyTitle2(driver, getExpectedAlerts());
1007         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
1008     }
1009 
1010     /**
1011      * @throws Exception if an error occurs
1012      */
1013     @Test
1014     @Alerts({"labelclick:label1", "parentclick:label1", "text1focus:text1",
1015              "text1click:text1", "labelclick:text1", "parentclick:text1"})
1016     public void clickForAndNestedEventBubbling() throws Exception {
1017         final String html =
1018               "  <div onclick='log(\"parentclick:\" + event.target.id)' "
1019                           + "onfocus='log(\"parentfocus:\" + event.target.id)'>\n"
1020               + "    <label id='label1' for='text1' onclick='log(\"labelclick:\" + event.target.id)' "
1021                           + "onfocus='log(\"labelfocus:\" + event.target.id)'>Click me"
1022               // we have to add some extra text to make Selenium click the label and not the nested element
1023               + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
1024               + "      <input type='text' id='text1' onclick='log(\"text1click:\" + event.target.id)' "
1025                           + "onfocus='log(\"text1focus:\" + event.target.id)'>\n"
1026               + "      <input type='text' id='text2' onclick='log(\"text2click:\" + event.target.id)' "
1027                           + "onfocus='log(\"text2focus:\" + event.target.id)'>\n"
1028               + "    </label>\n"
1029               + "  </div>\n";
1030         final WebDriver driver = loadPage2(generatePage(html));
1031         driver.findElement(By.id("label1")).click();
1032         verifyTitle2(driver, getExpectedAlerts());
1033         assertEquals(driver.findElement(By.id("text1")), driver.switchTo().activeElement());
1034     }
1035 
1036     /**
1037      * @throws Exception if an error occurs
1038      */
1039     @Test
1040     @Alerts({"labelclick", "text2focus", "text2click"})
1041     public void clickForVersusNested() throws Exception {
1042         final String html =
1043               "  <label id='label1' for='text2' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
1044             // we have to add some extra text to make Selenium click the label and not the nested element
1045             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
1046             + "    <input type='text' id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")'>\n"
1047             + "  </label>\n"
1048             + "  <input type='text' id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'>\n";
1049         final WebDriver driver = loadPage2(generatePage(html));
1050         driver.findElement(By.id("label1")).click();
1051         verifyTitle2(driver, getExpectedAlerts());
1052         assertEquals(driver.findElement(By.id("text2")), driver.switchTo().activeElement());
1053     }
1054 
1055     /**
1056      * @throws Exception if an error occurs
1057      */
1058     @Test
1059     @Alerts("labelclick")
1060     public void clickForUnknownVersusNested() throws Exception {
1061         final String html =
1062               "  <label id='label1' for='unknown' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
1063             // we have to add some extra text to make Selenium click the label and not the nested element
1064             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
1065             + "    <input type='text' id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")'>\n"
1066             + "  </label>\n"
1067             + "  <input type='text' id='text2' onclick='log(\"text2click\")' onfocus='log(\"text2focus\")'>\n";
1068         final WebDriver driver = loadPage2(generatePage(html));
1069         driver.findElement(By.id("label1")).click();
1070         verifyTitle2(driver, getExpectedAlerts());
1071         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
1072     }
1073 
1074     /**
1075      * @throws Exception if an error occurs
1076      */
1077     @Test
1078     @Alerts("labelclick")
1079     public void clickForNotLabelableVersusNested() throws Exception {
1080         final String html =
1081               "  <label id='label1' for='div1' onclick='log(\"labelclick\")' onfocus='log(\"labelfocus\")'>Click me"
1082             // we have to add some extra text to make Selenium click the label and not the nested element
1083             + " (we have to add some extra text to make Selenium click the label and not the nested element)\n"
1084             + "    <input type='text' id='text1' onclick='log(\"text1click\")' onfocus='log(\"text1focus\")'>\n"
1085             + "  </label>\n"
1086             + "  <div id='div1' onclick='log(\"div1click\")' onfocus='log(\"div1focus\")'></div>\n";
1087         final WebDriver driver = loadPage2(generatePage(html));
1088         driver.findElement(By.id("label1")).click();
1089         verifyTitle2(driver, getExpectedAlerts());
1090         assertEquals(driver.findElement(By.id("body")), driver.switchTo().activeElement());
1091     }
1092 
1093     /**
1094      * @throws Exception if an error occurs
1095      */
1096     @Test
1097     @Alerts({"click radio1Label", "click listItem1", "click list",
1098                 "click radio1", "click listItem1", "click list", "true"})
1099     public void triggerRadioFor() throws Exception {
1100         final String html =
1101               "  <ul onclick='log(\"click list\")'>\n"
1102             + "    <li onclick='log(\"click listItem1\")'>\n"
1103             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1104             + "      <input id='radio1' name='radios' value='1' type='radio' "
1105                         + "onclick='log(\"click radio1\");'>\n"
1106             + "    </li>\n"
1107             + "  </ul>\n"
1108             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1109         final WebDriver driver = loadPage2(generatePage(html));
1110         driver.findElement(By.id("radio1Label")).click();
1111         driver.findElement(By.id("check")).click();
1112         verifyTitle2(driver, getExpectedAlerts());
1113     }
1114 
1115     /**
1116      * @throws Exception if an error occurs
1117      */
1118     @Test
1119     @Alerts({"click radio1Label", "click listItem1", "click list",
1120                 "click radio1", "click radio1Label", "click listItem1", "click list", "true"})
1121     public void triggerRadioNested() throws Exception {
1122         final String html =
1123               "  <ul onclick='log(\"click list\")'>\n"
1124             + "    <li onclick='log(\"click listItem1\")'>\n"
1125             + "      <label id='radio1Label' onclick='log(\"click radio1Label\")'>Radio 1\n"
1126             + "        <input id='radio1' name='radios' value='1' type='radio' "
1127                           + "onclick='log(\"click radio1\");'>\n"
1128             + "      </label>"
1129             + "    </li>\n"
1130             + "  </ul>\n"
1131             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1132         final WebDriver driver = loadPage2(generatePage(html));
1133         driver.findElement(By.id("radio1Label")).click();
1134         driver.findElement(By.id("check")).click();
1135         verifyTitle2(driver, getExpectedAlerts());
1136     }
1137 
1138     /**
1139      * @throws Exception if an error occurs
1140      */
1141     @Test
1142     @Alerts({"click radio1Label", "click listItem1", "click list",
1143                 "click radio1", "click radio1Label", "click listItem1", "click list", "true"})
1144     public void triggerRadioForAndNested() throws Exception {
1145         final String html =
1146               "  <ul onclick='log(\"click list\")'>\n"
1147             + "    <li onclick='log(\"click listItem1\")'>\n"
1148             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1\n"
1149             + "        <input id='radio1' name='radios' value='1' type='radio' "
1150                           + "onclick='log(\"click radio1\");'>\n"
1151             + "      </label>"
1152             + "    </li>\n"
1153             + "  </ul>\n"
1154             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1155         final WebDriver driver = loadPage2(generatePage(html));
1156         driver.findElement(By.id("radio1Label")).click();
1157         driver.findElement(By.id("check")).click();
1158         verifyTitle2(driver, getExpectedAlerts());
1159     }
1160 
1161     /**
1162      * @throws Exception if an error occurs
1163      */
1164     @Test
1165     @Alerts({"click radio1Label", "click listItem1", "click list",
1166                 "click radio1", "click listItem1", "click list", "true"})
1167     public void triggerRadioCheckedFor() throws Exception {
1168         final String html =
1169               "  <ul onclick='log(\"click list\")'>\n"
1170             + "    <li onclick='log(\"click listItem1\")'>\n"
1171             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1172             + "      <input id='radio1' name='radios' value='1' type='radio' checked "
1173                         + "onclick='log(\"click radio1\");'>\n"
1174             + "    </li>\n"
1175             + "  </ul>\n"
1176             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1177         final WebDriver driver = loadPage2(generatePage(html));
1178         driver.findElement(By.id("radio1Label")).click();
1179         driver.findElement(By.id("check")).click();
1180         verifyTitle2(driver, getExpectedAlerts());
1181     }
1182 
1183     /**
1184      * @throws Exception if an error occurs
1185      */
1186     @Test
1187     @Alerts({"click radio1Label", "click listItem1", "click list",
1188                 "click radio1", "click radio1Label", "click listItem1", "click list", "true"})
1189     public void triggerRadioCheckedNested() throws Exception {
1190         final String html =
1191               "  <ul onclick='log(\"click list\")'>\n"
1192             + "    <li onclick='log(\"click listItem1\")'>\n"
1193             + "      <label id='radio1Label' onclick='log(\"click radio1Label\")'>Radio 1\n"
1194             + "        <input id='radio1' name='radios' value='1' type='radio' checked "
1195                           + "onclick='log(\"click radio1\");'>\n"
1196             + "      </label>"
1197             + "    </li>\n"
1198             + "  </ul>\n"
1199             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1200         final WebDriver driver = loadPage2(generatePage(html));
1201         driver.findElement(By.id("radio1Label")).click();
1202         driver.findElement(By.id("check")).click();
1203         verifyTitle2(driver, getExpectedAlerts());
1204     }
1205 
1206     /**
1207      * @throws Exception if an error occurs
1208      */
1209     @Test
1210     @Alerts({"click radio1Label", "click listItem1", "click list",
1211                 "click radio1", "click radio1Label", "click listItem1", "click list", "true"})
1212     public void triggerRadioCheckedForAndNested() throws Exception {
1213         final String html =
1214               "  <ul onclick='log(\"click list\")'>\n"
1215             + "    <li onclick='log(\"click listItem1\")'>\n"
1216             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1\n"
1217             + "        <input id='radio1' name='radios' value='1' type='radio' checked "
1218                           + "onclick='log(\"click radio1\");'>\n"
1219             + "      </label>"
1220             + "    </li>\n"
1221             + "  </ul>\n"
1222             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1223         final WebDriver driver = loadPage2(generatePage(html));
1224         driver.findElement(By.id("radio1Label")).click();
1225         driver.findElement(By.id("check")).click();
1226         verifyTitle2(driver, getExpectedAlerts());
1227     }
1228 
1229     /**
1230      * @throws Exception if an error occurs
1231      */
1232     @Test
1233     @Alerts({"click radio1Label", "click listItem1", "click list", "false"})
1234     public void triggerRadioDisabled() throws Exception {
1235         final String html =
1236               "  <ul onclick='log(\"click list\")'>\n"
1237             + "    <li onclick='log(\"click listItem1\")'>\n"
1238             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1239             + "      <input id='radio1' name='radios' value='1' type='radio' disabled "
1240                         + "onclick='log(\"click radio1\");'>\n"
1241             + "    </li>\n"
1242             + "  </ul>\n"
1243             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1244         final WebDriver driver = loadPage2(generatePage(html));
1245         driver.findElement(By.id("radio1Label")).click();
1246         driver.findElement(By.id("check")).click();
1247         verifyTitle2(driver, getExpectedAlerts());
1248     }
1249 
1250     /**
1251      * @throws Exception if an error occurs
1252      */
1253     @Test
1254     @Alerts({"click radio1Label", "click listItem1", "click list",
1255                 "click radio1", "click listItem1", "click list", "true"})
1256     public void triggerRadioNotDisplayed() throws Exception {
1257         final String html =
1258               "  <ul onclick='log(\"click list\")'>\n"
1259             + "    <li onclick='log(\"click listItem1\")'>\n"
1260             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1261             + "      <input id='radio1' name='radios' value='1' type='radio' style='display: none;' "
1262                         + "onclick='log(\"click radio1\");'>\n"
1263             + "    </li>\n"
1264             + "  </ul>\n"
1265             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1266         final WebDriver driver = loadPage2(generatePage(html));
1267         driver.findElement(By.id("radio1Label")).click();
1268         driver.findElement(By.id("check")).click();
1269         verifyTitle2(driver, getExpectedAlerts());
1270     }
1271 
1272     /**
1273      * @throws Exception if an error occurs
1274      */
1275     @Test
1276     @Alerts({"click radio1Label", "click listItem1", "click list",
1277                 "click radio1", "click listItem1", "click list", "true"})
1278     public void triggerRadioNotVisible() throws Exception {
1279         final String html =
1280               "  <ul onclick='log(\"click list\")'>\n"
1281             + "    <li onclick='log(\"click listItem1\")'>\n"
1282             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1283             + "      <input id='radio1' name='radios' value='1' type='radio' style='visibility: hidden;' "
1284                         + "onclick='log(\"click radio1\");'>\n"
1285             + "    </li>\n"
1286             + "  </ul>\n"
1287             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1288         final WebDriver driver = loadPage2(generatePage(html));
1289         driver.findElement(By.id("radio1Label")).click();
1290         driver.findElement(By.id("check")).click();
1291         verifyTitle2(driver, getExpectedAlerts());
1292     }
1293 
1294     /**
1295      * @throws Exception if an error occurs
1296      */
1297     @Test
1298     @Alerts({"click radio1Label", "click listItem1", "click list",
1299                 "click radio1", "click listItem1", "click list", "true"})
1300     public void triggerRadioHidden() throws Exception {
1301         final String html =
1302               "  <ul onclick='log(\"click list\")'>\n"
1303             + "    <li onclick='log(\"click listItem1\")'>\n"
1304             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Radio 1</label>\n"
1305             + "      <input id='radio1' name='radios' value='1' type='radio' hidden "
1306                         + "onclick='log(\"click radio1\");'>\n"
1307             + "    </li>\n"
1308             + "  </ul>\n"
1309             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1310         final WebDriver driver = loadPage2(generatePage(html));
1311         driver.findElement(By.id("radio1Label")).click();
1312         driver.findElement(By.id("check")).click();
1313         verifyTitle2(driver, getExpectedAlerts());
1314     }
1315 
1316     /**
1317      * @throws Exception if an error occurs
1318      */
1319     @Test
1320     @Alerts({"click span1", "click radio1Label", "click listItem1", "click list",
1321                 "click radio1", "click radio1Label",
1322                 "click listItem1", "click list", "true"})
1323     public void triggerRadioComplexCase() throws Exception {
1324         final String html =
1325               "  <ul onclick='log(\"click list\")'>\n"
1326             + "    <li onclick='log(\"click listItem1\")'>\n"
1327             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>\n"
1328             + "        <span>\n"
1329             + "          <input id='radio1' name='radios' value='1' type='radio' "
1330                             + "onclick='log(\"click radio1\");'>\n"
1331             + "          <span id='radio1Span' onclick='log(\"click span1\")'>Radio 1</span>\n"
1332             + "        </span>\n"
1333             + "      </label>\n"
1334             + "    </li>\n"
1335             + "  </ul>\n"
1336             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1337         final WebDriver driver = loadPage2(generatePage(html));
1338         driver.findElement(By.id("radio1Span")).click();
1339         driver.findElement(By.id("check")).click();
1340         verifyTitle2(driver, getExpectedAlerts());
1341     }
1342 
1343     /**
1344      * @throws Exception if an error occurs
1345      */
1346     @Test
1347     @Alerts({"click span1", "click radio1Label", "click listItem1", "click list",
1348                 "click radio1", "click radio1Label",
1349                 "click listItem1", "click list", "true"})
1350     public void triggerRadioComplexCaseChecked() throws Exception {
1351         final String html =
1352               "  <ul onclick='log(\"click list\")'>\n"
1353             + "    <li onclick='log(\"click listItem1\")'>\n"
1354             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>\n"
1355             + "        <span>\n"
1356             + "          <input id='radio1' name='radios' value='1' type='radio' checked "
1357                             + "onclick='log(\"click radio1\");'>\n"
1358             + "          <span id='radio1Span' onclick='log(\"click span1\")'>Radio 1</span>\n"
1359             + "        </span>\n"
1360             + "      </label>\n"
1361             + "    </li>\n"
1362             + "  </ul>\n"
1363             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1364         final WebDriver driver = loadPage2(generatePage(html));
1365         driver.findElement(By.id("radio1Span")).click();
1366         driver.findElement(By.id("check")).click();
1367         verifyTitle2(driver, getExpectedAlerts());
1368     }
1369 
1370     /**
1371      * @throws Exception if an error occurs
1372      */
1373     @Test
1374     @Alerts({"click span1", "click radio1Label", "click listItem1", "click list",
1375                 "click radio1", "click radio1Label",
1376                 "click listItem1", "click list", "true"})
1377     public void triggerRadioComplexCaseInvisible() throws Exception {
1378         final String html =
1379               "  <ul onclick='log(\"click list\")'>\n"
1380             + "    <li onclick='log(\"click listItem1\")'>\n"
1381             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>\n"
1382             + "        <span>\n"
1383             + "          <input id='radio1' name='radios' value='1' type='radio' style='display: none;' "
1384                             + "onclick='log(\"click radio1\");'>\n"
1385             + "          <span id='radio1Span' onclick='log(\"click span1\")'>Radio 1</span>\n"
1386             + "        </span>\n"
1387             + "      </label>\n"
1388             + "    </li>\n"
1389             + "  </ul>\n"
1390             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1391         final WebDriver driver = loadPage2(generatePage(html));
1392         driver.findElement(By.id("radio1Span")).click();
1393         driver.findElement(By.id("check")).click();
1394         verifyTitle2(driver, getExpectedAlerts());
1395     }
1396 
1397     /**
1398      * @throws Exception if an error occurs
1399      */
1400     @Test
1401     @Alerts({"click span1", "click radio1Label", "click listItem1", "click list",
1402                 "click radio1", "click radio1Label",
1403                 "click listItem1", "click list", "true"})
1404     public void triggerRadioComplexCaseHidden() throws Exception {
1405         final String html =
1406               "  <ul onclick='log(\"click list\")'>\n"
1407             + "    <li onclick='log(\"click listItem1\")'>\n"
1408             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>\n"
1409             + "        <span>\n"
1410             + "          <input id='radio1' name='radios' value='1' type='radio' hidden "
1411                             + "onclick='log(\"click radio1\");'>\n"
1412             + "          <span id='radio1Span' onclick='log(\"click span1\")'>Radio 1</span>\n"
1413             + "        </span>\n"
1414             + "      </label>\n"
1415             + "    </li>\n"
1416             + "  </ul>\n"
1417             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1418         final WebDriver driver = loadPage2(generatePage(html));
1419         driver.findElement(By.id("radio1Span")).click();
1420         driver.findElement(By.id("check")).click();
1421         verifyTitle2(driver, getExpectedAlerts());
1422     }
1423 
1424     /**
1425      * @throws Exception if an error occurs
1426      */
1427     @Test
1428     @Alerts({"click span1", "click radio1Label", "click listItem1", "click list", "false"})
1429     public void triggerRadioComplexCaseDisabled() throws Exception {
1430         final String html =
1431               "  <ul onclick='log(\"click list\")'>\n"
1432             + "    <li onclick='log(\"click listItem1\")'>\n"
1433             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>\n"
1434             + "        <span>\n"
1435             + "          <input id='radio1' name='radios' value='1' type='radio' disabled "
1436                             + "onclick='log(\"click radio1\");'>\n"
1437             + "          <span id='radio1Span' onclick='log(\"click span1\")'>Radio 1</span>\n"
1438             + "        </span>\n"
1439             + "      </label>\n"
1440             + "    </li>\n"
1441             + "  </ul>\n"
1442             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1443         final WebDriver driver = loadPage2(generatePage(html));
1444         driver.findElement(By.id("radio1Span")).click();
1445         driver.findElement(By.id("check")).click();
1446         verifyTitle2(driver, getExpectedAlerts());
1447     }
1448 
1449     /**
1450      * @throws Exception if an error occurs
1451      */
1452     @Test
1453     @Alerts({"click radio1Label", "click listItem1", "click list",
1454                 "click radio1", "click radio1Label",
1455                 "click listItem1", "click list", "true"})
1456     public void triggerRadioComplexCaseChildOfLabel() throws Exception {
1457         final String html =
1458               "  <ul onclick='log(\"click list\")'>\n"
1459             + "    <li onclick='log(\"click listItem1\")'>\n"
1460             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Label\n"
1461             + "        <input id='radio1' name='radios' value='1' type='radio'"
1462                           + "onclick='log(\"click radio1\");'>\n"
1463             + "      </label>\n"
1464             + "    </li>\n"
1465             + "  </ul>\n"
1466             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1467         final WebDriver driver = loadPage2(generatePage(html));
1468         driver.findElement(By.id("radio1Label")).click();
1469         driver.findElement(By.id("check")).click();
1470         verifyTitle2(driver, getExpectedAlerts());
1471     }
1472 
1473     /**
1474      * @throws Exception if an error occurs
1475      */
1476     @Test
1477     @Alerts({"click radio1", "click radio1Label", "click listItem1", "click list", "true"})
1478     public void triggerRadioComplexCaseClickRadio() throws Exception {
1479         final String html =
1480               "  <ul onclick='log(\"click list\")'>\n"
1481             + "    <li onclick='log(\"click listItem1\")'>\n"
1482             + "      <label id='radio1Label' for='radio1' onclick='log(\"click radio1Label\")'>Label\n"
1483             + "        <input id='radio1' name='radios' value='1' type='radio'"
1484                           + "onclick='log(\"click radio1\");'>\n"
1485             + "      </label>\n"
1486             + "    </li>\n"
1487             + "  </ul>\n"
1488             + "  <button id='check' onclick='log(document.getElementById(\"radio1\").checked)'>Check</button>\n";
1489         final WebDriver driver = loadPage2(generatePage(html));
1490         driver.findElement(By.id("radio1")).click();
1491         driver.findElement(By.id("check")).click();
1492         verifyTitle2(driver, getExpectedAlerts());
1493     }
1494 
1495     /**
1496      * @throws Exception if an error occurs
1497      */
1498     @Test
1499     @Alerts({"click check1Label", "click listItem1", "click list",
1500                 "click check1", "click listItem1", "click list", "true"})
1501     public void triggerCheckboxFor() throws Exception {
1502         final String html =
1503               "  <ul onclick='log(\"click list\")'>\n"
1504             + "    <li onclick='log(\"click listItem1\")'>\n"
1505             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1506             + "      <input id='check1' name='checks' value='1' type='checkbox' "
1507                         + "onclick='log(\"click check1\");'>\n"
1508             + "    </li>\n"
1509             + "  </ul>\n"
1510             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1511         final WebDriver driver = loadPage2(generatePage(html));
1512         driver.findElement(By.id("check1Label")).click();
1513         driver.findElement(By.id("check")).click();
1514         verifyTitle2(driver, getExpectedAlerts());
1515     }
1516 
1517     /**
1518      * @throws Exception if an error occurs
1519      */
1520     @Test
1521     @Alerts({"click check1Label", "click listItem1", "click list",
1522                 "click check1", "click check1Label", "click listItem1", "click list", "true"})
1523     public void triggerCheckboxNested() throws Exception {
1524         final String html =
1525               "  <ul onclick='log(\"click list\")'>\n"
1526             + "    <li onclick='log(\"click listItem1\")'>\n"
1527             + "      <label id='check1Label' onclick='log(\"click check1Label\")'>Checkbox 1\n"
1528             + "        <input id='check1' name='checks' value='1' type='checkbox' "
1529                           + "onclick='log(\"click check1\");'>\n"
1530             + "      </label>\n"
1531             + "    </li>\n"
1532             + "  </ul>\n"
1533             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1534         final WebDriver driver = loadPage2(generatePage(html));
1535         driver.findElement(By.id("check1Label")).click();
1536         driver.findElement(By.id("check")).click();
1537         verifyTitle2(driver, getExpectedAlerts());
1538     }
1539 
1540     /**
1541      * @throws Exception if an error occurs
1542      */
1543     @Test
1544     @Alerts({"click check1Label", "click listItem1", "click list",
1545                 "click check1", "click check1Label", "click listItem1", "click list", "true"})
1546     public void triggerCheckboxForAndNested() throws Exception {
1547         final String html =
1548               "  <ul onclick='log(\"click list\")'>\n"
1549             + "    <li onclick='log(\"click listItem1\")'>\n"
1550             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1\n"
1551             + "        <input id='check1' name='checks' value='1' type='checkbox' "
1552                           + "onclick='log(\"click check1\");'>\n"
1553             + "      </label>\n"
1554             + "    </li>\n"
1555             + "  </ul>\n"
1556             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1557         final WebDriver driver = loadPage2(generatePage(html));
1558         driver.findElement(By.id("check1Label")).click();
1559         driver.findElement(By.id("check")).click();
1560         verifyTitle2(driver, getExpectedAlerts());
1561     }
1562 
1563     /**
1564      * @throws Exception if an error occurs
1565      */
1566     @Test
1567     @Alerts({"click check1Label", "click listItem1", "click list",
1568                 "click check1", "click listItem1", "click list", "false"})
1569     public void triggerCheckboxCheckedFor() throws Exception {
1570         final String html =
1571               "  <ul onclick='log(\"click list\")'>\n"
1572             + "    <li onclick='log(\"click listItem1\")'>\n"
1573             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1574             + "      <input id='check1' name='checks' value='1' type='checkbox' checked "
1575                         + "onclick='log(\"click check1\");'>\n"
1576             + "    </li>\n"
1577             + "  </ul>\n"
1578             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1579         final WebDriver driver = loadPage2(generatePage(html));
1580         driver.findElement(By.id("check1Label")).click();
1581         driver.findElement(By.id("check")).click();
1582         verifyTitle2(driver, getExpectedAlerts());
1583     }
1584 
1585     /**
1586      * @throws Exception if an error occurs
1587      */
1588     @Test
1589     @Alerts({"click check1Label", "click listItem1", "click list",
1590                 "click check1", "click check1Label", "click listItem1", "click list", "false"})
1591     public void triggerCheckboxCheckedNested() throws Exception {
1592         final String html =
1593               "  <ul onclick='log(\"click list\")'>\n"
1594             + "    <li onclick='log(\"click listItem1\")'>\n"
1595             + "      <label id='check1Label' onclick='log(\"click check1Label\")'>Checkbox 1\n"
1596             + "        <input id='check1' name='checks' value='1' type='checkbox' checked "
1597                           + "onclick='log(\"click check1\");'>\n"
1598             + "      </label>\n"
1599             + "    </li>\n"
1600             + "  </ul>\n"
1601             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1602         final WebDriver driver = loadPage2(generatePage(html));
1603         driver.findElement(By.id("check1Label")).click();
1604         driver.findElement(By.id("check")).click();
1605         verifyTitle2(driver, getExpectedAlerts());
1606     }
1607 
1608     /**
1609      * @throws Exception if an error occurs
1610      */
1611     @Test
1612     @Alerts({"click check1Label", "click listItem1", "click list",
1613                 "click check1", "click check1Label", "click listItem1", "click list", "false"})
1614     public void triggerCheckboxCheckedForAndNested() throws Exception {
1615         final String html =
1616               "  <ul onclick='log(\"click list\")'>\n"
1617             + "    <li onclick='log(\"click listItem1\")'>\n"
1618             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1\n"
1619             + "        <input id='check1' name='checks' value='1' type='checkbox' checked "
1620                           + "onclick='log(\"click check1\");'>\n"
1621             + "      </label>\n"
1622             + "    </li>\n"
1623             + "  </ul>\n"
1624             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1625         final WebDriver driver = loadPage2(generatePage(html));
1626         driver.findElement(By.id("check1Label")).click();
1627         driver.findElement(By.id("check")).click();
1628         verifyTitle2(driver, getExpectedAlerts());
1629     }
1630 
1631     /**
1632      * @throws Exception if an error occurs
1633      */
1634     @Test
1635     @Alerts({"click check1Label", "click listItem1", "click list", "false"})
1636     public void triggerCheckboxDisabled() throws Exception {
1637         final String html =
1638               "  <ul onclick='log(\"click list\")'>\n"
1639             + "    <li onclick='log(\"click listItem1\")'>\n"
1640             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1641             + "      <input id='check1' name='checks' value='1' type='checkbox' disabled "
1642                         + "onclick='log(\"click check1\");'>\n"
1643             + "    </li>\n"
1644             + "  </ul>\n"
1645             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1646         final WebDriver driver = loadPage2(generatePage(html));
1647         driver.findElement(By.id("check1Label")).click();
1648         driver.findElement(By.id("check")).click();
1649         verifyTitle2(driver, getExpectedAlerts());
1650     }
1651 
1652     /**
1653      * @throws Exception if an error occurs
1654      */
1655     @Test
1656     @Alerts({"click check1Label", "click listItem1", "click list",
1657                 "click check1", "click listItem1", "click list", "true"})
1658     public void triggerCheckboxNotDisplayed() throws Exception {
1659         final String html =
1660               "  <ul onclick='log(\"click list\")'>\n"
1661             + "    <li onclick='log(\"click listItem1\")'>\n"
1662             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1663             + "      <input id='check1' name='checks' value='1' type='checkbox' style='display: none;' "
1664                         + "onclick='log(\"click check1\");'>\n"
1665             + "    </li>\n"
1666             + "  </ul>\n"
1667             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1668         final WebDriver driver = loadPage2(generatePage(html));
1669         driver.findElement(By.id("check1Label")).click();
1670         driver.findElement(By.id("check")).click();
1671         verifyTitle2(driver, getExpectedAlerts());
1672     }
1673 
1674     /**
1675      * @throws Exception if an error occurs
1676      */
1677     @Test
1678     @Alerts({"click check1Label", "click listItem1", "click list",
1679                 "click check1", "click listItem1", "click list", "true"})
1680     public void triggerCheckboxNotVisible() throws Exception {
1681         final String html =
1682               "  <ul onclick='log(\"click list\")'>\n"
1683             + "    <li onclick='log(\"click listItem1\")'>\n"
1684             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1685             + "      <input id='check1' name='checks' value='1' type='checkbox' style='visibility: hidden;' "
1686                         + "onclick='log(\"click check1\");'>\n"
1687             + "    </li>\n"
1688             + "  </ul>\n"
1689             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1690         final WebDriver driver = loadPage2(generatePage(html));
1691         driver.findElement(By.id("check1Label")).click();
1692         driver.findElement(By.id("check")).click();
1693         verifyTitle2(driver, getExpectedAlerts());
1694     }
1695 
1696     /**
1697      * @throws Exception if an error occurs
1698      */
1699     @Test
1700     @Alerts({"click check1Label", "click listItem1", "click list",
1701                 "click check1", "click listItem1", "click list", "true"})
1702     public void triggerCheckboxHidden() throws Exception {
1703         final String html =
1704               "  <ul onclick='log(\"click list\")'>\n"
1705             + "    <li onclick='log(\"click listItem1\")'>\n"
1706             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Checkbox 1</label>\n"
1707             + "      <input id='check1' name='checks' value='1' type='checkbox' hidden "
1708                         + "onclick='log(\"click check1\");'>\n"
1709             + "    </li>\n"
1710             + "  </ul>\n"
1711             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1712         final WebDriver driver = loadPage2(generatePage(html));
1713         driver.findElement(By.id("check1Label")).click();
1714         driver.findElement(By.id("check")).click();
1715         verifyTitle2(driver, getExpectedAlerts());
1716     }
1717 
1718     /**
1719      * @throws Exception if an error occurs
1720      */
1721     @Test
1722     @Alerts({"click span1", "click check1Label", "click listItem1", "click list",
1723                 "click check1", "click check1Label",
1724                 "click listItem1", "click list", "true"})
1725     public void triggerCheckboxComplexCase() throws Exception {
1726         final String html =
1727               "  <ul onclick='log(\"click list\")'>\n"
1728             + "    <li onclick='log(\"click listItem1\")'>\n"
1729             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>\n"
1730             + "        <span>\n"
1731             + "          <input id='check1' name='checks' value='1' type='checkbox' "
1732                             + "onclick='log(\"click check1\");'>\n"
1733             + "          <span id='check1Span' onclick='log(\"click span1\")'>Checkbox 1</span>\n"
1734             + "        </span>\n"
1735             + "      </label>\n"
1736             + "    </li>\n"
1737             + "  </ul>\n"
1738             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1739         final WebDriver driver = loadPage2(generatePage(html));
1740         driver.findElement(By.id("check1Span")).click();
1741         driver.findElement(By.id("check")).click();
1742         verifyTitle2(driver, getExpectedAlerts());
1743     }
1744 
1745     /**
1746      * @throws Exception if an error occurs
1747      */
1748     @Test
1749     @Alerts({"click span1", "click check1Label", "click listItem1", "click list",
1750                 "click check1", "click check1Label",
1751                 "click listItem1", "click list", "false"})
1752     public void triggerCheckboxComplexCaseChecked() throws Exception {
1753         final String html =
1754               "  <ul onclick='log(\"click list\")'>\n"
1755             + "    <li onclick='log(\"click listItem1\")'>\n"
1756             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>\n"
1757             + "        <span>\n"
1758             + "          <input id='check1' name='checks' value='1' type='checkbox' checked "
1759                             + "onclick='log(\"click check1\");'>\n"
1760             + "          <span id='check1Span' onclick='log(\"click span1\")'>Checkbox 1</span>\n"
1761             + "        </span>\n"
1762             + "      </label>\n"
1763             + "    </li>\n"
1764             + "  </ul>\n"
1765             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1766         final WebDriver driver = loadPage2(generatePage(html));
1767         driver.findElement(By.id("check1Span")).click();
1768         driver.findElement(By.id("check")).click();
1769         verifyTitle2(driver, getExpectedAlerts());
1770     }
1771 
1772     /**
1773      * @throws Exception if an error occurs
1774      */
1775     @Test
1776     @Alerts({"click span1", "click check1Label", "click listItem1", "click list",
1777                 "click check1", "click check1Label",
1778                 "click listItem1", "click list", "true"})
1779     public void triggerCheckboxComplexCaseInvisible() throws Exception {
1780         final String html =
1781               "  <ul onclick='log(\"click list\")'>\n"
1782             + "    <li onclick='log(\"click listItem1\")'>\n"
1783             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>\n"
1784             + "        <span>\n"
1785             + "          <input id='check1' name='checks' value='1' type='checkbox' style='display: none;' "
1786                             + "onclick='log(\"click check1\");'>\n"
1787             + "          <span id='check1Span' onclick='log(\"click span1\")'>Checkbox 1</span>\n"
1788             + "        </span>\n"
1789             + "      </label>\n"
1790             + "    </li>\n"
1791             + "  </ul>\n"
1792             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1793         final WebDriver driver = loadPage2(generatePage(html));
1794         driver.findElement(By.id("check1Span")).click();
1795         driver.findElement(By.id("check")).click();
1796         verifyTitle2(driver, getExpectedAlerts());
1797     }
1798 
1799     /**
1800      * @throws Exception if an error occurs
1801      */
1802     @Test
1803     @Alerts({"click span1", "click check1Label", "click listItem1", "click list",
1804                 "click check1", "click check1Label",
1805                 "click listItem1", "click list", "true"})
1806     public void triggerCheckboxComplexCaseHidden() throws Exception {
1807         final String html =
1808               "  <ul onclick='log(\"click list\")'>\n"
1809             + "    <li onclick='log(\"click listItem1\")'>\n"
1810             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>\n"
1811             + "        <span>\n"
1812             + "          <input id='check1' name='checks' value='1' type='checkbox' hidden "
1813                             + "onclick='log(\"click check1\");'>\n"
1814             + "          <span id='check1Span' onclick='log(\"click span1\")'>Checkbox 1</span>\n"
1815             + "        </span>\n"
1816             + "      </label>\n"
1817             + "    </li>\n"
1818             + "  </ul>\n"
1819             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1820         final WebDriver driver = loadPage2(generatePage(html));
1821         driver.findElement(By.id("check1Span")).click();
1822         driver.findElement(By.id("check")).click();
1823         verifyTitle2(driver, getExpectedAlerts());
1824     }
1825 
1826     /**
1827      * @throws Exception if an error occurs
1828      */
1829     @Test
1830     @Alerts({"click span1", "click check1Label", "click listItem1", "click list", "false"})
1831     public void triggerCheckboxComplexCaseDisabled() throws Exception {
1832         final String html =
1833               "  <ul onclick='log(\"click list\")'>\n"
1834             + "    <li onclick='log(\"click listItem1\")'>\n"
1835             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>\n"
1836             + "        <span>\n"
1837             + "          <input id='check1' name='checks' value='1' type='checkbox' disabled "
1838                             + "onclick='log(\"click check1\");'>\n"
1839             + "          <span id='check1Span' onclick='log(\"click span1\")'>Checkbox 1</span>\n"
1840             + "        </span>\n"
1841             + "      </label>\n"
1842             + "    </li>\n"
1843             + "  </ul>\n"
1844             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1845         final WebDriver driver = loadPage2(generatePage(html));
1846         driver.findElement(By.id("check1Span")).click();
1847         driver.findElement(By.id("check")).click();
1848         verifyTitle2(driver, getExpectedAlerts());
1849     }
1850 
1851     /**
1852      * @throws Exception if an error occurs
1853      */
1854     @Test
1855     @Alerts({"click check1Label", "click listItem1", "click list",
1856                 "click check1", "click check1Label",
1857                 "click listItem1", "click list", "true"})
1858     public void triggerCheckboxComplexCaseChildOfLabel() throws Exception {
1859         final String html =
1860               "  <ul onclick='log(\"click list\")'>\n"
1861             + "    <li onclick='log(\"click listItem1\")'>\n"
1862             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Label\n"
1863             + "        <input id='check1' name='checks' value='1' type='checkbox'"
1864                           + "onclick='log(\"click check1\");'>\n"
1865             + "      </label>\n"
1866             + "    </li>\n"
1867             + "  </ul>\n"
1868             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1869         final WebDriver driver = loadPage2(generatePage(html));
1870         driver.findElement(By.id("check1Label")).click();
1871         driver.findElement(By.id("check")).click();
1872         verifyTitle2(driver, getExpectedAlerts());
1873     }
1874 
1875     /**
1876      * @throws Exception if an error occurs
1877      */
1878     @Test
1879     @Alerts({"click check1", "click check1Label", "click listItem1", "click list", "true"})
1880     public void triggerCheckboxComplexCaseClickCheckbox() throws Exception {
1881         final String html =
1882               "  <ul onclick='log(\"click list\")'>\n"
1883             + "    <li onclick='log(\"click listItem1\")'>\n"
1884             + "      <label id='check1Label' for='check1' onclick='log(\"click check1Label\")'>Label\n"
1885             + "        <input id='check1' name='checks' value='1' type='checkbox'"
1886                           + "onclick='log(\"click check1\");'>\n"
1887             + "      </label>\n"
1888             + "    </li>\n"
1889             + "  </ul>\n"
1890             + "  <button id='check' onclick='log(document.getElementById(\"check1\").checked)'>Check</button>\n";
1891 
1892         final WebDriver driver = loadPage2(generatePage(html));
1893         driver.findElement(By.id("check1")).click();
1894         driver.findElement(By.id("check")).click();
1895         verifyTitle2(driver, getExpectedAlerts());
1896     }
1897 
1898     private static String generatePage(final String snippet) {
1899         return DOCTYPE_HTML
1900             + "<html>\n"
1901             + "  <head>\n"
1902             + "    <script>\n"
1903             + LOG_TITLE_FUNCTION
1904             + "    </script>\n"
1905             + "  </head>\n"
1906             + "  <body id='body'>\n"
1907             + snippet
1908             + "  </body>\n"
1909             + "</html>";
1910     }
1911 }