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