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.serializer;
16  
17  import static java.nio.charset.StandardCharsets.ISO_8859_1;
18  
19  import org.htmlunit.WebDriverTestCase;
20  import org.htmlunit.html.DomNode;
21  import org.htmlunit.html.HtmlPage;
22  import org.htmlunit.html.serializer.HtmlSerializerVisibleText.HtmlSerializerTextBuilder;
23  import org.htmlunit.junit.BrowserRunner;
24  import org.htmlunit.junit.annotation.Alerts;
25  import org.htmlunit.junit.annotation.HtmlUnitNYI;
26  import org.htmlunit.xml.XmlPage;
27  import org.junit.Test;
28  import org.junit.runner.RunWith;
29  import org.openqa.selenium.By;
30  import org.openqa.selenium.WebDriver;
31  import org.openqa.selenium.WebElement;
32  import org.openqa.selenium.htmlunit.HtmlUnitDriver;
33  
34  /**
35   * Tests for {@link HtmlSerializerVisibleText}.
36   * This contains the tests for plain controls.
37   *
38   * @author Ronald Brill
39   * @author cd alexndr
40   */
41  @RunWith(BrowserRunner.class)
42  public class HtmlSerializerVisibleText2Test extends WebDriverTestCase {
43  
44      /**
45       * Test {@link HtmlSerializerTextBuilder} special spaces.
46       * @throws Exception if the test fails
47       */
48      @Test
49      @Alerts(CHROME = "",
50              EDGE = "",
51              FF = "\n    baz\n  ",
52              FF_ESR = "\n    baz\n  ")
53      @HtmlUnitNYI(CHROME = "baz",
54              EDGE = "baz",
55              FF = "baz",
56              FF_ESR = "baz")
57      public void xmlPage() throws Exception {
58          final String xml = "<xml>\n"
59                  + "  <foo>\n"
60                  + "    <bar>baz</bar>\n"
61                  + "  </foo>\n"
62                  + "</xml>";
63          final WebDriver driver = loadPage2(xml, URL_FIRST, "text/xml;charset=ISO-8859-1", ISO_8859_1);
64          final String text = driver.findElement(By.xpath("//foo")).getText();
65          assertEquals(getExpectedAlerts()[0], text);
66  
67          if (driver instanceof HtmlUnitDriver) {
68              final XmlPage page = (XmlPage) getEnclosedPage();
69              final DomNode node = page.getFirstByXPath("//foo");
70              assertEquals(getExpectedAlerts()[0], node.getVisibleText());
71          }
72      }
73  
74      /**
75       * Verifies getVisibleText().
76       * @throws Exception if the test fails
77       */
78      @Test
79      @Alerts("")
80      public void getVisibleTextWhiteSpaceBreak() throws Exception {
81          getVisibleTextWhiteSpaceBreak(null);
82      }
83  
84      /**
85       * Verifies getVisibleText().
86       * @throws Exception if the test fails
87       */
88      @Test
89      @Alerts("")
90      public void getVisibleTextWhiteSpaceBreakNormal() throws Exception {
91          getVisibleTextWhiteSpaceBreak("normal");
92      }
93  
94      /**
95       * Verifies getVisibleText().
96       * @throws Exception if the test fails
97       */
98      @Test
99      @Alerts("")
100     public void getVisibleTextWhiteSpaceBreakNowrap() throws Exception {
101         getVisibleTextWhiteSpaceBreak("nowrap");
102     }
103 
104     /**
105      * Verifies getVisibleText().
106      * @throws Exception if the test fails
107      */
108     @Test
109     @Alerts("")
110     public void getVisibleTextWhiteSpaceBreakPre() throws Exception {
111         getVisibleTextWhiteSpaceBreak("pre");
112     }
113 
114     /**
115      * Verifies getVisibleText().
116      * @throws Exception if the test fails
117      */
118     @Test
119     @Alerts("")
120     public void getVisibleTextWhiteSpaceBreakPreWrap() throws Exception {
121         getVisibleTextWhiteSpaceBreak("pre-wrap");
122     }
123 
124     /**
125      * Verifies getVisibleText().
126      * @throws Exception if the test fails
127      */
128     @Test
129     @Alerts("")
130     public void getVisibleTextWhiteSpaceBreakPreLine() throws Exception {
131         getVisibleTextWhiteSpaceBreak("pre-line");
132     }
133 
134     private void getVisibleTextWhiteSpaceBreak(final String whiteSpace) throws Exception {
135         final String htmlContent = DOCTYPE_HTML
136             + "<html>\n"
137             + "<head></head>\n"
138             + "<body>\n"
139             + "  <br id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
140             + "</body></html>";
141 
142         final WebDriver driver = loadPage2(htmlContent);
143         final String text = driver.findElement(By.id("tester")).getText();
144         assertEquals(getExpectedAlerts()[0], text);
145 
146         if (driver instanceof HtmlUnitDriver) {
147             final HtmlPage page = (HtmlPage) getEnclosedPage();
148             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
149             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
150         }
151     }
152 
153     /**
154      * Verifies getVisibleText().
155      * @throws Exception if the test fails
156      */
157     @Test
158     @Alerts("")
159     public void getVisibleTextWhiteSpaceInputHidden() throws Exception {
160         getVisibleTextWhiteSpaceInputHidden(null);
161     }
162 
163     /**
164      * Verifies getVisibleText().
165      * @throws Exception if the test fails
166      */
167     @Test
168     @Alerts("")
169     public void getVisibleTextWhiteSpaceInputHiddenNormal() throws Exception {
170         getVisibleTextWhiteSpaceInputHidden("normal");
171     }
172 
173     /**
174      * Verifies getVisibleText().
175      * @throws Exception if the test fails
176      */
177     @Test
178     @Alerts("")
179     public void getVisibleTextWhiteSpaceInputHiddenNowrap() throws Exception {
180         getVisibleTextWhiteSpaceInputHidden("nowrap");
181     }
182 
183     /**
184      * Verifies getVisibleText().
185      * @throws Exception if the test fails
186      */
187     @Test
188     @Alerts("")
189     public void getVisibleTextWhiteSpaceInputHiddenPre() throws Exception {
190         getVisibleTextWhiteSpaceInputHidden("pre");
191     }
192 
193     /**
194      * Verifies getVisibleText().
195      * @throws Exception if the test fails
196      */
197     @Test
198     @Alerts("")
199     public void getVisibleTextWhiteSpaceInputHiddenPreWrap() throws Exception {
200         getVisibleTextWhiteSpaceInputHidden("pre-wrap");
201     }
202 
203     /**
204      * Verifies getVisibleText().
205      * @throws Exception if the test fails
206      */
207     @Test
208     @Alerts("")
209     public void getVisibleTextWhiteSpaceInputHiddenPreLine() throws Exception {
210         getVisibleTextWhiteSpaceInputHidden("pre-line");
211     }
212 
213     private void getVisibleTextWhiteSpaceInputHidden(final String whiteSpace) throws Exception {
214         final String htmlContent = DOCTYPE_HTML
215             + "<html>\n"
216             + "<head></head>\n"
217             + "<body>\n"
218             + "<form id='form1'>\n"
219             + "  <input type='hidden' name='tester' id='tester' "
220                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
221                         + " value='  A B  C\t \t  D \r\nEF\nG \n H  <br> I  '>\n"
222             + "</form>\n"
223             + "</body></html>";
224 
225         final WebDriver driver = loadPage2(htmlContent);
226         final String text = driver.findElement(By.id("tester")).getText();
227         assertEquals(getExpectedAlerts()[0], text);
228 
229         if (driver instanceof HtmlUnitDriver) {
230             final HtmlPage page = (HtmlPage) getEnclosedPage();
231             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
232             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
233         }
234     }
235 
236     /**
237      * Verifies getVisibleText().
238      * @throws Exception if the test fails
239      */
240     @Test
241     @Alerts("")
242     public void getVisibleTextWhiteSpaceScript() throws Exception {
243         getVisibleTextWhiteSpaceScript(null);
244     }
245 
246     /**
247      * Verifies getVisibleText().
248      * @throws Exception if the test fails
249      */
250     @Test
251     @Alerts("")
252     public void getVisibleTextWhiteSpaceScriptNormal() throws Exception {
253         getVisibleTextWhiteSpaceScript("normal");
254     }
255 
256     /**
257      * Verifies getVisibleText().
258      * @throws Exception if the test fails
259      */
260     @Test
261     @Alerts("")
262     public void getVisibleTextWhiteSpaceScriptNowrap() throws Exception {
263         getVisibleTextWhiteSpaceScript("nowrap");
264     }
265 
266     /**
267      * Verifies getVisibleText().
268      * @throws Exception if the test fails
269      */
270     @Test
271     @Alerts("")
272     public void getVisibleTextWhiteSpaceScriptPre() throws Exception {
273         getVisibleTextWhiteSpaceScript("pre");
274     }
275 
276     /**
277      * Verifies getVisibleText().
278      * @throws Exception if the test fails
279      */
280     @Test
281     @Alerts("")
282     public void getVisibleTextWhiteSpaceScriptPreWrap() throws Exception {
283         getVisibleTextWhiteSpaceScript("pre-wrap");
284     }
285 
286     /**
287      * Verifies getVisibleText().
288      * @throws Exception if the test fails
289      */
290     @Test
291     @Alerts("")
292     public void getVisibleTextWhiteSpaceScriptPreLine() throws Exception {
293         getVisibleTextWhiteSpaceScript("pre-line");
294     }
295 
296     private void getVisibleTextWhiteSpaceScript(final String whiteSpace) throws Exception {
297         final String htmlContent = DOCTYPE_HTML
298             + "<html>\n"
299             + "<head></head>\n"
300             + "<body>\n"
301             + "  <script id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
302                 + "var x;  \n \t   \r\n var y;</script>\n"
303             + "</body></html>";
304 
305         final WebDriver driver = loadPage2(htmlContent);
306         final String text = driver.findElement(By.id("tester")).getText();
307         assertEquals(getExpectedAlerts()[0], text);
308 
309         if (driver instanceof HtmlUnitDriver) {
310             final HtmlPage page = (HtmlPage) getEnclosedPage();
311             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
312             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
313         }
314     }
315 
316     /**
317      * Verifies getVisibleText().
318      * @throws Exception if the test fails
319      */
320     @Test
321     @Alerts("")
322     public void getVisibleTextWhiteSpaceStyle() throws Exception {
323         getVisibleTextWhiteSpaceStyle(null);
324     }
325 
326     /**
327      * Verifies getVisibleText().
328      * @throws Exception if the test fails
329      */
330     @Test
331     @Alerts("")
332     public void getVisibleTextWhiteSpaceStyleNormal() throws Exception {
333         getVisibleTextWhiteSpaceStyle("normal");
334     }
335 
336     /**
337      * Verifies getVisibleText().
338      * @throws Exception if the test fails
339      */
340     @Test
341     @Alerts("")
342     public void getVisibleTextWhiteSpaceStyleNowrap() throws Exception {
343         getVisibleTextWhiteSpaceStyle("nowrap");
344     }
345 
346     /**
347      * Verifies getVisibleText().
348      * @throws Exception if the test fails
349      */
350     @Test
351     @Alerts("")
352     public void getVisibleTextWhiteSpaceStylePre() throws Exception {
353         getVisibleTextWhiteSpaceStyle("pre");
354     }
355 
356     /**
357      * Verifies getVisibleText().
358      * @throws Exception if the test fails
359      */
360     @Test
361     @Alerts("")
362     public void getVisibleTextWhiteSpaceStylePreWrap() throws Exception {
363         getVisibleTextWhiteSpaceStyle("pre-wrap");
364     }
365 
366     /**
367      * Verifies getVisibleText().
368      * @throws Exception if the test fails
369      */
370     @Test
371     @Alerts("")
372     public void getVisibleTextWhiteSpaceStylePreLine() throws Exception {
373         getVisibleTextWhiteSpaceStyle("pre-line");
374     }
375 
376     private void getVisibleTextWhiteSpaceStyle(final String whiteSpace) throws Exception {
377         final String htmlContent = DOCTYPE_HTML
378             + "<html>\n"
379             + "<head></head>\n"
380             + "<body>\n"
381             + "  <style id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
382                 + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </style>\n"
383             + "</body></html>";
384 
385         final WebDriver driver = loadPage2(htmlContent);
386         final String text = driver.findElement(By.id("tester")).getText();
387         assertEquals(getExpectedAlerts()[0], text);
388 
389         if (driver instanceof HtmlUnitDriver) {
390             final HtmlPage page = (HtmlPage) getEnclosedPage();
391             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
392             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
393         }
394     }
395 
396     /**
397      * Verifies getVisibleText().
398      * @throws Exception if the test fails
399      */
400     @Test
401     @Alerts("")
402     public void getVisibleTextWhiteSpaceNoframes() throws Exception {
403         getVisibleTextWhiteSpaceNoframes(null);
404     }
405 
406     /**
407      * Verifies getVisibleText().
408      * @throws Exception if the test fails
409      */
410     @Test
411     @Alerts("")
412     public void getVisibleTextWhiteSpaceNoframesNormal() throws Exception {
413         getVisibleTextWhiteSpaceNoframes("normal");
414     }
415 
416     /**
417      * Verifies getVisibleText().
418      * @throws Exception if the test fails
419      */
420     @Test
421     @Alerts("")
422     public void getVisibleTextWhiteSpaceNoframesNowrap() throws Exception {
423         getVisibleTextWhiteSpaceNoframes("nowrap");
424     }
425 
426     /**
427      * Verifies getVisibleText().
428      * @throws Exception if the test fails
429      */
430     @Test
431     @Alerts("")
432     public void getVisibleTextWhiteSpaceNoframesPre() throws Exception {
433         getVisibleTextWhiteSpaceNoframes("pre");
434     }
435 
436     /**
437      * Verifies getVisibleText().
438      * @throws Exception if the test fails
439      */
440     @Test
441     @Alerts("")
442     public void getVisibleTextWhiteSpaceNoframesPreWrap() throws Exception {
443         getVisibleTextWhiteSpaceNoframes("pre-wrap");
444     }
445 
446     /**
447      * Verifies getVisibleText().
448      * @throws Exception if the test fails
449      */
450     @Test
451     @Alerts("")
452     public void getVisibleTextWhiteSpaceNoframesPreLine() throws Exception {
453         getVisibleTextWhiteSpaceNoframes("pre-line");
454     }
455 
456     private void getVisibleTextWhiteSpaceNoframes(final String whiteSpace) throws Exception {
457         final String htmlContent = DOCTYPE_HTML
458             + "<html>\n"
459             + "<head></head>\n"
460             + "<body>\n"
461             + "  <noframes id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
462                 + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </noframes>\n"
463             + "</body></html>";
464 
465         final WebDriver driver = loadPage2(htmlContent);
466         final String text = driver.findElement(By.id("tester")).getText();
467         assertEquals(getExpectedAlerts()[0], text);
468 
469         if (driver instanceof HtmlUnitDriver) {
470             final HtmlPage page = (HtmlPage) getEnclosedPage();
471             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
472             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
473         }
474     }
475 
476     /**
477      * Verifies getVisibleText().
478      * @throws Exception if the test fails
479      */
480     @Test
481     @Alerts("A B C D EF G H\nI")
482     public void getVisibleTextWhiteSpaceDiv() throws Exception {
483         getVisibleTextWhiteSpaceDiv(null);
484     }
485 
486     /**
487      * Verifies getVisibleText().
488      * @throws Exception if the test fails
489      */
490     @Test
491     @Alerts("A B C D EF G H\nI")
492     public void getVisibleTextWhiteSpaceDivNormal() throws Exception {
493         getVisibleTextWhiteSpaceDiv("normal");
494     }
495 
496     /**
497      * Verifies getVisibleText().
498      * @throws Exception if the test fails
499      */
500     @Test
501     @Alerts("A B C D EF G H\nI")
502     public void getVisibleTextWhiteSpaceDivNowrap() throws Exception {
503         getVisibleTextWhiteSpaceDiv("nowrap");
504     }
505 
506     /**
507      * Verifies getVisibleText().
508      * @throws Exception if the test fails
509      */
510     @Test
511     @Alerts("  A B  C     D \nEF\nG \n H  \n I  ")
512     public void getVisibleTextWhiteSpaceDivPre() throws Exception {
513         getVisibleTextWhiteSpaceDiv("pre");
514     }
515 
516     /**
517      * Verifies getVisibleText().
518      * @throws Exception if the test fails
519      */
520     @Test
521     @Alerts("  A B  C     D \nEF\nG \n H  \n I  ")
522     public void getVisibleTextWhiteSpaceDivPreWrap() throws Exception {
523         getVisibleTextWhiteSpaceDiv("pre-wrap");
524     }
525 
526     /**
527      * Verifies getVisibleText().
528      * @throws Exception if the test fails
529      */
530     @Test
531     @Alerts("A B C D \nEF\nG \n H\nI")
532     public void getVisibleTextWhiteSpaceDivPreLine() throws Exception {
533         getVisibleTextWhiteSpaceDiv("pre-line");
534     }
535 
536     private void getVisibleTextWhiteSpaceDiv(final String whiteSpace) throws Exception {
537         final String htmlContent = DOCTYPE_HTML
538             + "<html>\n"
539             + "<head></head>\n"
540             + "<body>\n"
541             + "  <div id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
542                 + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </div>\n"
543             + "</body></html>";
544 
545         final WebDriver driver = loadPage2(htmlContent);
546         final String text = driver.findElement(By.id("tester")).getText();
547         assertEquals(getExpectedAlerts()[0], text);
548 
549         if (driver instanceof HtmlUnitDriver) {
550             final HtmlPage page = (HtmlPage) getEnclosedPage();
551             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
552             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
553         }
554     }
555 
556     /**
557      * Verifies getVisibleText().
558      * @throws Exception if the test fails
559      */
560     @Test
561     @Alerts("  A B  C     D \nEF\nG \n H  \n I  ")
562     public void getVisibleTextWhiteSpacePre() throws Exception {
563         getVisibleTextWhiteSpacePre(null);
564     }
565 
566     /**
567      * Verifies getVisibleText().
568      * @throws Exception if the test fails
569      */
570     @Test
571     @Alerts("A B C D EF G H\nI")
572     public void getVisibleTextWhiteSpacePreNormal() throws Exception {
573         getVisibleTextWhiteSpacePre("normal");
574     }
575 
576     /**
577      * Verifies getVisibleText().
578      * @throws Exception if the test fails
579      */
580     @Test
581     @Alerts("A B C D EF G H\nI")
582     public void getVisibleTextWhiteSpacePreNowrap() throws Exception {
583         getVisibleTextWhiteSpacePre("nowrap");
584     }
585 
586     /**
587      * Verifies getVisibleText().
588      * @throws Exception if the test fails
589      */
590     @Test
591     @Alerts("  A B  C     D \nEF\nG \n H  \n I  ")
592     public void getVisibleTextWhiteSpacePrePre() throws Exception {
593         getVisibleTextWhiteSpacePre("pre");
594     }
595 
596     /**
597      * Verifies getVisibleText().
598      * @throws Exception if the test fails
599      */
600     @Test
601     @Alerts("  A B  C     D \nEF\nG \n H  \n I  ")
602     public void getVisibleTextWhiteSpacePrePreWrap() throws Exception {
603         getVisibleTextWhiteSpacePre("pre-wrap");
604     }
605 
606     /**
607      * Verifies getVisibleText().
608      * @throws Exception if the test fails
609      */
610     @Test
611     @Alerts("A B C D \nEF\nG \n H\nI")
612     public void getVisibleTextWhiteSpacePrePreLine() throws Exception {
613         getVisibleTextWhiteSpacePre("pre-line");
614     }
615 
616     private void getVisibleTextWhiteSpacePre(final String whiteSpace) throws Exception {
617         final String htmlContent = DOCTYPE_HTML
618             + "<html>\n"
619             + "<head></head>\n"
620             + "<body>\n"
621             + "  <pre id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
622                     + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </pre>\n"
623             + "</body></html>";
624 
625         final WebDriver driver = loadPage2(htmlContent);
626         final String text = driver.findElement(By.id("tester")).getText();
627         assertEquals(getExpectedAlerts()[0], text);
628 
629         if (driver instanceof HtmlUnitDriver) {
630             final HtmlPage page = (HtmlPage) getEnclosedPage();
631             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
632             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
633         }
634     }
635 
636     /**
637      * Verifies getVisibleText().
638      * @throws Exception if the test fails
639      */
640     @Test
641     @Alerts("  A B  C     D \nEF\nG \n H  <br> I  ")
642     public void getVisibleTextWhiteSpaceTextArea() throws Exception {
643         getVisibleTextWhiteSpaceTextArea(null);
644     }
645 
646     /**
647      * Verifies getVisibleText().
648      * @throws Exception if the test fails
649      */
650     @Test
651     @Alerts("A B C D EF G H <br> I")
652     public void getVisibleTextWhiteSpaceTextAreaNormal() throws Exception {
653         getVisibleTextWhiteSpaceTextArea("normal");
654     }
655 
656     /**
657      * Verifies getVisibleText().
658      * @throws Exception if the test fails
659      */
660     @Test
661     @Alerts("A B C D EF G H <br> I")
662     public void getVisibleTextWhiteSpaceTextAreaNowrap() throws Exception {
663         getVisibleTextWhiteSpaceTextArea("nowrap");
664     }
665 
666     /**
667      * Verifies getVisibleText().
668      * @throws Exception if the test fails
669      */
670     @Test
671     @Alerts("  A B  C     D \nEF\nG \n H  <br> I  ")
672     public void getVisibleTextWhiteSpaceTextAreaPre() throws Exception {
673         getVisibleTextWhiteSpaceTextArea("pre");
674     }
675 
676     /**
677      * Verifies getVisibleText().
678      * @throws Exception if the test fails
679      */
680     @Test
681     @Alerts("  A B  C     D \nEF\nG \n H  <br> I  ")
682     public void getVisibleTextWhiteSpaceTextAreaPreWrap() throws Exception {
683         getVisibleTextWhiteSpaceTextArea("pre-wrap");
684     }
685 
686     /**
687      * Verifies getVisibleText().
688      * @throws Exception if the test fails
689      */
690     @Test
691     @Alerts("A B C D \nEF\nG \n H <br> I")
692     public void getVisibleTextWhiteSpaceTextAreaPreLine() throws Exception {
693         getVisibleTextWhiteSpaceTextArea("pre-line");
694     }
695 
696     private void getVisibleTextWhiteSpaceTextArea(final String whiteSpace) throws Exception {
697         final String htmlContent = DOCTYPE_HTML
698             + "<html>\n"
699             + "<head></head>\n"
700             + "<body>\n"
701             + "  <textarea id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
702                     + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </textarea>\n"
703             + "</body></html>";
704 
705         final WebDriver driver = loadPage2(htmlContent);
706         final String text = driver.findElement(By.id("tester")).getText();
707         assertEquals(getExpectedAlerts()[0], text);
708 
709         if (driver instanceof HtmlUnitDriver) {
710             final HtmlPage page = (HtmlPage) getEnclosedPage();
711             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
712             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
713         }
714     }
715 
716     /**
717      * Verifies getVisibleText().
718      * @throws Exception if the test fails
719      */
720     @Test
721     @Alerts("")
722     public void getVisibleTextWhiteSpaceTitle() throws Exception {
723         getVisibleTextWhiteSpaceTitle(null);
724     }
725 
726     /**
727      * Verifies getVisibleText().
728      * @throws Exception if the test fails
729      */
730     @Test
731     @Alerts("")
732     public void getVisibleTextWhiteSpaceTitleNormal() throws Exception {
733         getVisibleTextWhiteSpaceTitle("normal");
734     }
735 
736     /**
737      * Verifies getVisibleText().
738      * @throws Exception if the test fails
739      */
740     @Test
741     @Alerts("")
742     public void getVisibleTextWhiteSpaceTitleNowrap() throws Exception {
743         getVisibleTextWhiteSpaceTitle("nowrap");
744     }
745 
746     /**
747      * Verifies getVisibleText().
748      * @throws Exception if the test fails
749      */
750     @Test
751     @Alerts("")
752     public void getVisibleTextWhiteSpaceTitlePre() throws Exception {
753         getVisibleTextWhiteSpaceTitle("pre");
754     }
755 
756     /**
757      * Verifies getVisibleText().
758      * @throws Exception if the test fails
759      */
760     @Test
761     @Alerts("")
762     public void getVisibleTextWhiteSpaceTitlePreWrap() throws Exception {
763         getVisibleTextWhiteSpaceTitle("pre-wrap");
764     }
765 
766     /**
767      * Verifies getVisibleText().
768      * @throws Exception if the test fails
769      */
770     @Test
771     @Alerts("")
772     public void getVisibleTextWhiteSpaceTitlePreLine() throws Exception {
773         getVisibleTextWhiteSpaceTitle("pre-line");
774     }
775 
776     private void getVisibleTextWhiteSpaceTitle(final String whiteSpace) throws Exception {
777         final String htmlContent = DOCTYPE_HTML
778             + "<html>\n"
779             + "<head>\n"
780             + "<title id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
781             + "  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </title>\n"
782             + "</head>\n"
783             + "<body>\n"
784             + "</body></html>";
785 
786         final WebDriver driver = loadPage2(htmlContent);
787         final String text = driver.findElement(By.id("tester")).getText();
788         assertEquals(getExpectedAlerts()[0], text);
789 
790         if (driver instanceof HtmlUnitDriver) {
791             final HtmlPage page = (HtmlPage) getEnclosedPage();
792             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
793             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
794         }
795     }
796 
797     /**
798      * Verifies getVisibleText().
799      * @throws Exception if the test fails
800      */
801     @Test
802     @Alerts(DEFAULT = "       A B C D EF G H\nI\n      Second\n    ",
803             FF = "A B C D EF G H I\nSecond",
804             FF_ESR = "A B C D EF G H I\nSecond")
805     @HtmlUnitNYI(CHROME = "A B C D EF G H I\nSecond",
806             EDGE = "A B C D EF G H I\nSecond")
807     public void getVisibleTextWhiteSpaceSelect() throws Exception {
808         getVisibleTextWhiteSpaceSelect(null);
809     }
810 
811     /**
812      * Verifies getVisibleText().
813      * @throws Exception if the test fails
814      */
815     @Test
816     @Alerts(DEFAULT = "A B C D EF G H\nI\nSecond",
817             FF = "A B C D EF G H I\nSecond",
818             FF_ESR = "A B C D EF G H I\nSecond")
819     @HtmlUnitNYI(CHROME = "A B C D EF G H I\nSecond",
820             EDGE = "A B C D EF G H I\nSecond")
821     public void getVisibleTextWhiteSpaceSelectNormal() throws Exception {
822         getVisibleTextWhiteSpaceSelect("normal");
823     }
824 
825     /**
826      * Verifies getVisibleText().
827      * @throws Exception if the test fails
828      */
829     @Test
830     @Alerts(DEFAULT = "A B C D EF G H\nI\nSecond",
831             FF = "A B C D EF G H I\nSecond",
832             FF_ESR = "A B C D EF G H I\nSecond")
833     @HtmlUnitNYI(CHROME = "A B C D EF G H I\nSecond",
834             EDGE = "A B C D EF G H I\nSecond")
835     public void getVisibleTextWhiteSpaceSelectNowrap() throws Exception {
836         getVisibleTextWhiteSpaceSelect("nowrap");
837     }
838 
839     /**
840      * Verifies getVisibleText().
841      * @throws Exception if the test fails
842      */
843     @Test
844     @Alerts(DEFAULT = "       A B C D EF G H\nI\n      Second\n    ",
845             FF = "A B C D EF G H I\nSecond",
846             FF_ESR = "A B C D EF G H I\nSecond")
847     @HtmlUnitNYI(CHROME = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
848             EDGE = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
849             FF = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
850             FF_ESR = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ")
851     public void getVisibleTextWhiteSpaceSelectPre() throws Exception {
852         getVisibleTextWhiteSpaceSelect("pre");
853     }
854 
855     /**
856      * Verifies getVisibleText().
857      * @throws Exception if the test fails
858      */
859     @Test
860     @Alerts(DEFAULT = "       A B C D EF G H\nI\n      Second\n    ",
861             FF = "A B C D EF G H I\nSecond",
862             FF_ESR = "A B C D EF G H I\nSecond")
863     @HtmlUnitNYI(CHROME = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
864             EDGE = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
865             FF = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ",
866             FF_ESR = "        A B  C     D \nEF\nG \n H   I  \n      Second\n    ")
867     public void getVisibleTextWhiteSpaceSelectPreWrap() throws Exception {
868         getVisibleTextWhiteSpaceSelect("pre-wrap");
869     }
870 
871     /**
872      * Verifies getVisibleText().
873      * @throws Exception if the test fails
874      */
875     @Test
876     @Alerts(DEFAULT = "A B C D EF G H\nI\nSecond",
877             FF = "A B C D EF G H I\nSecond",
878             FF_ESR = "A B C D EF G H I\nSecond")
879     @HtmlUnitNYI(CHROME = "A B C D \nEF\nG \n H I\n Second",
880             EDGE = "A B C D \nEF\nG \n H I\n Second",
881             FF = "A B C D \nEF\nG \n H I\n Second",
882             FF_ESR = "A B C D \nEF\nG \n H I\n Second")
883     public void getVisibleTextWhiteSpaceSelectPreLine() throws Exception {
884         getVisibleTextWhiteSpaceSelect("pre-line");
885     }
886 
887     private void getVisibleTextWhiteSpaceSelect(final String whiteSpace) throws Exception {
888         final String htmlContent = DOCTYPE_HTML
889             + "<html>\n"
890             + "<head></head>\n"
891             + "<body>\n"
892             + "  <form>\n"
893             + "    <select id='tester' "
894                     + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
895             + "      <option>  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </option>\n"
896             + "      <option>Second</option>\n"
897             + "    </select>\n"
898             + "</body></html>";
899 
900         final WebDriver driver = loadPage2(htmlContent);
901         final String text = driver.findElement(By.id("tester")).getText();
902         assertEquals(getExpectedAlerts()[0], text);
903 
904         if (driver instanceof HtmlUnitDriver) {
905             final HtmlPage page = (HtmlPage) getEnclosedPage();
906             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
907             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
908         }
909     }
910 
911     /**
912      * Verifies getVisibleText().
913      * @throws Exception if the test fails
914      */
915     @Test
916     @Alerts("")
917     public void getVisibleTextWhiteSpaceInputSubmit() throws Exception {
918         getVisibleTextWhiteSpaceInputSubmit(null);
919     }
920 
921     /**
922      * Verifies getVisibleText().
923      * @throws Exception if the test fails
924      */
925     @Test
926     @Alerts("")
927     public void getVisibleTextWhiteSpaceInputSubmitNormal() throws Exception {
928         getVisibleTextWhiteSpaceInputSubmit("normal");
929     }
930 
931     /**
932      * Verifies getVisibleText().
933      * @throws Exception if the test fails
934      */
935     @Test
936     @Alerts("")
937     public void getVisibleTextWhiteSpaceInputSubmitNowrap() throws Exception {
938         getVisibleTextWhiteSpaceInputSubmit("nowrap");
939     }
940 
941     /**
942      * Verifies getVisibleText().
943      * @throws Exception if the test fails
944      */
945     @Test
946     @Alerts("")
947     public void getVisibleTextWhiteSpaceInputSubmitPre() throws Exception {
948         getVisibleTextWhiteSpaceInputSubmit("pre");
949     }
950 
951     /**
952      * Verifies getVisibleText().
953      * @throws Exception if the test fails
954      */
955     @Test
956     @Alerts("")
957     public void getVisibleTextWhiteSpaceInputSubmitPreWrap() throws Exception {
958         getVisibleTextWhiteSpaceInputSubmit("pre-wrap");
959     }
960 
961     /**
962      * Verifies getVisibleText().
963      * @throws Exception if the test fails
964      */
965     @Test
966     @Alerts("")
967     public void getVisibleTextWhiteSpaceInputSubmitPreLine() throws Exception {
968         getVisibleTextWhiteSpaceInputSubmit("pre-line");
969     }
970 
971     private void getVisibleTextWhiteSpaceInputSubmit(final String whiteSpace) throws Exception {
972         final String htmlContent = DOCTYPE_HTML
973             + "<html>\n"
974             + "<head></head>\n"
975             + "<body>\n"
976             + "<form id='form1'>\n"
977             + "  <input type='submit' name='tester' id='tester' "
978                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
979                         + " value='  A B  C\t \t  D \r\nEF\nG \n H  <br> I  '>\n"
980             + "</form>\n"
981             + "</body></html>";
982 
983         final WebDriver driver = loadPage2(htmlContent);
984         final String text = driver.findElement(By.id("tester")).getText();
985         assertEquals(getExpectedAlerts()[0], text);
986 
987         if (driver instanceof HtmlUnitDriver) {
988             final HtmlPage page = (HtmlPage) getEnclosedPage();
989             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
990             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
991         }
992     }
993 
994     /**
995      * Verifies getVisibleText().
996      * @throws Exception if the test fails
997      */
998     @Test
999     @Alerts("")
1000     public void getVisibleTextInputSubmitNoValue() throws Exception {
1001         final String htmlContent = DOCTYPE_HTML
1002             + "<html>\n"
1003             + "<head></head>\n"
1004             + "<body>\n"
1005             + "<form id='form1'>\n"
1006             + "  <input type='submit' name='tester' id='tester' >\n"
1007             + "</form>\n"
1008             + "</body></html>";
1009 
1010         final WebDriver driver = loadPage2(htmlContent);
1011         final String text = driver.findElement(By.id("tester")).getText();
1012         assertEquals(getExpectedAlerts()[0], text);
1013 
1014         if (driver instanceof HtmlUnitDriver) {
1015             final HtmlPage page = (HtmlPage) getEnclosedPage();
1016             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1017             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1018         }
1019     }
1020 
1021     /**
1022      * Verifies getVisibleText().
1023      * @throws Exception if the test fails
1024      */
1025     @Test
1026     @Alerts("")
1027     public void getVisibleTextInputResetNoValue() throws Exception {
1028         final String htmlContent = DOCTYPE_HTML
1029             + "<html>\n"
1030             + "<head></head>\n"
1031             + "<body>\n"
1032             + "<form id='form1'>\n"
1033             + "  <input type='reset' name='tester' id='tester' >\n"
1034             + "</form>\n"
1035             + "</body></html>";
1036 
1037         final WebDriver driver = loadPage2(htmlContent);
1038         final String text = driver.findElement(By.id("tester")).getText();
1039         assertEquals(getExpectedAlerts()[0], text);
1040 
1041         if (driver instanceof HtmlUnitDriver) {
1042             final HtmlPage page = (HtmlPage) getEnclosedPage();
1043             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1044             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1045         }
1046     }
1047 
1048     /**
1049      * Verifies getVisibleText().
1050      * @throws Exception if the test fails
1051      */
1052     @Test
1053     @Alerts("")
1054     public void getVisibleTextInputResetBlankValue() throws Exception {
1055         final String htmlContent = DOCTYPE_HTML
1056             + "<html>\n"
1057             + "<head></head>\n"
1058             + "<body>\n"
1059             + "<form id='form1'>\n"
1060             + "  <input type='reset' name='tester' id='tester' value='  \t'>\n"
1061             + "</form>\n"
1062             + "</body></html>";
1063 
1064         final WebDriver driver = loadPage2(htmlContent);
1065         final String text = driver.findElement(By.id("tester")).getText();
1066         assertEquals(getExpectedAlerts()[0], text);
1067 
1068         if (driver instanceof HtmlUnitDriver) {
1069             final HtmlPage page = (HtmlPage) getEnclosedPage();
1070             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1071             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1072         }
1073     }
1074 
1075     /**
1076      * Verifies getVisibleText().
1077      * @throws Exception if the test fails
1078      */
1079     @Test
1080     @Alerts("")
1081     public void getVisibleTextInputSubmitBlankValue() throws Exception {
1082         final String htmlContent = DOCTYPE_HTML
1083             + "<html>\n"
1084             + "<head></head>\n"
1085             + "<body>\n"
1086             + "<form id='form1'>\n"
1087             + "  <input type='submit' name='tester' id='tester' value='  \t'>\n"
1088             + "</form>\n"
1089             + "</body></html>";
1090 
1091         final WebDriver driver = loadPage2(htmlContent);
1092         final String text = driver.findElement(By.id("tester")).getText();
1093         assertEquals(getExpectedAlerts()[0], text);
1094 
1095         if (driver instanceof HtmlUnitDriver) {
1096             final HtmlPage page = (HtmlPage) getEnclosedPage();
1097             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1098             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1099         }
1100     }
1101 
1102     /**
1103      * Verifies getVisibleText().
1104      * @throws Exception if the test fails
1105      */
1106     @Test
1107     @Alerts("")
1108     public void getVisibleTextWhiteSpaceInputReset() throws Exception {
1109         getVisibleTextWhiteSpaceInputReset(null);
1110     }
1111 
1112     /**
1113      * Verifies getVisibleText().
1114      * @throws Exception if the test fails
1115      */
1116     @Test
1117     @Alerts("")
1118     public void getVisibleTextWhiteSpaceInputResetNormal() throws Exception {
1119         getVisibleTextWhiteSpaceInputReset("normal");
1120     }
1121 
1122     /**
1123      * Verifies getVisibleText().
1124      * @throws Exception if the test fails
1125      */
1126     @Test
1127     @Alerts("")
1128     public void getVisibleTextWhiteSpaceInputResetNowrap() throws Exception {
1129         getVisibleTextWhiteSpaceInputReset("nowrap");
1130     }
1131 
1132     /**
1133      * Verifies getVisibleText().
1134      * @throws Exception if the test fails
1135      */
1136     @Test
1137     @Alerts("")
1138     public void getVisibleTextWhiteSpaceInputResetPre() throws Exception {
1139         getVisibleTextWhiteSpaceInputReset("pre");
1140     }
1141 
1142     /**
1143      * Verifies getVisibleText().
1144      * @throws Exception if the test fails
1145      */
1146     @Test
1147     @Alerts("")
1148     public void getVisibleTextWhiteSpaceInputResetPreWrap() throws Exception {
1149         getVisibleTextWhiteSpaceInputReset("pre-wrap");
1150     }
1151 
1152     /**
1153      * Verifies getVisibleText().
1154      * @throws Exception if the test fails
1155      */
1156     @Test
1157     @Alerts("")
1158     public void getVisibleTextWhiteSpaceInputResetPreLine() throws Exception {
1159         getVisibleTextWhiteSpaceInputReset("pre-line");
1160     }
1161 
1162     private void getVisibleTextWhiteSpaceInputReset(final String whiteSpace) throws Exception {
1163         final String htmlContent = DOCTYPE_HTML
1164             + "<html>\n"
1165             + "<head></head>\n"
1166             + "<body>\n"
1167             + "<form id='form1'>\n"
1168             + "  <input type='reset' name='tester' id='tester' "
1169                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1170                         + " value='  A B  C\t \t  D \r\nEF\nG \n H  <br> I  '>\n"
1171             + "</form>\n"
1172             + "</body></html>";
1173 
1174         final WebDriver driver = loadPage2(htmlContent);
1175         final String text = driver.findElement(By.id("tester")).getText();
1176         assertEquals(getExpectedAlerts()[0], text);
1177 
1178         if (driver instanceof HtmlUnitDriver) {
1179             final HtmlPage page = (HtmlPage) getEnclosedPage();
1180             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1181             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1182         }
1183     }
1184 
1185     /**
1186      * Verifies getVisibleText().
1187      * @throws Exception if the test fails
1188      */
1189     @Test
1190     @Alerts("")
1191     public void getVisibleTextWhiteSpaceInputCheckbox() throws Exception {
1192         getVisibleTextWhiteSpaceInputCheckbox(null);
1193     }
1194 
1195     /**
1196      * Verifies getVisibleText().
1197      * @throws Exception if the test fails
1198      */
1199     @Test
1200     @Alerts("")
1201     public void getVisibleTextWhiteSpaceInputCheckboxNormal() throws Exception {
1202         getVisibleTextWhiteSpaceInputCheckbox("normal");
1203     }
1204 
1205     /**
1206      * Verifies getVisibleText().
1207      * @throws Exception if the test fails
1208      */
1209     @Test
1210     @Alerts("")
1211     public void getVisibleTextWhiteSpaceInputCheckboxNowrap() throws Exception {
1212         getVisibleTextWhiteSpaceInputCheckbox("nowrap");
1213     }
1214 
1215     /**
1216      * Verifies getVisibleText().
1217      * @throws Exception if the test fails
1218      */
1219     @Test
1220     @Alerts("")
1221     public void getVisibleTextWhiteSpaceInputCheckboxPre() throws Exception {
1222         getVisibleTextWhiteSpaceInputCheckbox("pre");
1223     }
1224 
1225     /**
1226      * Verifies getVisibleText().
1227      * @throws Exception if the test fails
1228      */
1229     @Test
1230     @Alerts("")
1231     public void getVisibleTextWhiteSpaceInputCheckboxPreWrap() throws Exception {
1232         getVisibleTextWhiteSpaceInputCheckbox("pre-wrap");
1233     }
1234 
1235     /**
1236      * Verifies getVisibleText().
1237      * @throws Exception if the test fails
1238      */
1239     @Test
1240     @Alerts("")
1241     public void getVisibleTextWhiteSpaceInputCheckboxPreLine() throws Exception {
1242         getVisibleTextWhiteSpaceInputCheckbox("pre-line");
1243     }
1244 
1245     private void getVisibleTextWhiteSpaceInputCheckbox(final String whiteSpace) throws Exception {
1246         final String htmlContent = DOCTYPE_HTML
1247             + "<html>\n"
1248             + "<head></head>\n"
1249             + "<body>\n"
1250             + "<form id='form1'>\n"
1251             + "  <input type='checkbox' name='tester' id='tester' "
1252                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1253                         + " value='  A B  C\t \t  D \r\nEF\nG \n H  <br> I  '>\n"
1254             + "</form>\n"
1255             + "</body></html>";
1256 
1257         final WebDriver driver = loadPage2(htmlContent);
1258         final String text = driver.findElement(By.id("tester")).getText();
1259         assertEquals(getExpectedAlerts()[0], text);
1260 
1261         if (driver instanceof HtmlUnitDriver) {
1262             final HtmlPage page = (HtmlPage) getEnclosedPage();
1263             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1264             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1265         }
1266     }
1267 
1268     /**
1269      * Verifies getVisibleText().
1270      * @throws Exception if the test fails
1271      */
1272     @Test
1273     @Alerts("")
1274     public void getVisibleTextWhiteSpaceInputRadio() throws Exception {
1275         getVisibleTextWhiteSpaceInputRadio(null);
1276     }
1277 
1278     /**
1279      * Verifies getVisibleText().
1280      * @throws Exception if the test fails
1281      */
1282     @Test
1283     @Alerts("")
1284     public void getVisibleTextWhiteSpaceInputRadioNormal() throws Exception {
1285         getVisibleTextWhiteSpaceInputRadio("normal");
1286     }
1287 
1288     /**
1289      * Verifies getVisibleText().
1290      * @throws Exception if the test fails
1291      */
1292     @Test
1293     @Alerts("")
1294     public void getVisibleTextWhiteSpaceInputRadioNowrap() throws Exception {
1295         getVisibleTextWhiteSpaceInputRadio("nowrap");
1296     }
1297 
1298     /**
1299      * Verifies getVisibleText().
1300      * @throws Exception if the test fails
1301      */
1302     @Test
1303     @Alerts("")
1304     public void getVisibleTextWhiteSpaceInputRadioPre() throws Exception {
1305         getVisibleTextWhiteSpaceInputRadio("pre");
1306     }
1307 
1308     /**
1309      * Verifies getVisibleText().
1310      * @throws Exception if the test fails
1311      */
1312     @Test
1313     @Alerts("")
1314     public void getVisibleTextWhiteSpaceInputRadioPreWrap() throws Exception {
1315         getVisibleTextWhiteSpaceInputRadio("pre-wrap");
1316     }
1317 
1318     /**
1319      * Verifies getVisibleText().
1320      * @throws Exception if the test fails
1321      */
1322     @Test
1323     @Alerts("")
1324     public void getVisibleTextWhiteSpaceInputRadioPreLine() throws Exception {
1325         getVisibleTextWhiteSpaceInputRadio("pre-line");
1326     }
1327 
1328     private void getVisibleTextWhiteSpaceInputRadio(final String whiteSpace) throws Exception {
1329         final String htmlContent = DOCTYPE_HTML
1330             + "<html>\n"
1331             + "<head></head>\n"
1332             + "<body>\n"
1333             + "<form id='form1'>\n"
1334             + "  <input type='radio' name='tester' id='tester' "
1335                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1336                         + " value='  A B  C\t \t  D \r\nEF\nG \n H  <br> I  '>\n"
1337             + "</form>\n"
1338             + "</body></html>";
1339 
1340         final WebDriver driver = loadPage2(htmlContent);
1341         final String text = driver.findElement(By.id("tester")).getText();
1342         assertEquals(getExpectedAlerts()[0], text);
1343 
1344         if (driver instanceof HtmlUnitDriver) {
1345             final HtmlPage page = (HtmlPage) getEnclosedPage();
1346             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1347             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1348         }
1349     }
1350 
1351     /**
1352      * Verifies getVisibleText().
1353      * @throws Exception if the test fails
1354      */
1355     @Test
1356     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1357     public void getVisibleTextWhiteSpaceOrderedList() throws Exception {
1358         getVisibleTextWhiteSpaceOrderedList(null);
1359     }
1360 
1361     /**
1362      * Verifies getVisibleText().
1363      * @throws Exception if the test fails
1364      */
1365     @Test
1366     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1367     public void getVisibleTextWhiteSpaceOrderedListNormal() throws Exception {
1368         getVisibleTextWhiteSpaceOrderedList("normal");
1369     }
1370 
1371     /**
1372      * Verifies getVisibleText().
1373      * @throws Exception if the test fails
1374      */
1375     @Test
1376     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1377     public void getVisibleTextWhiteSpaceOrderedListNowrap() throws Exception {
1378         getVisibleTextWhiteSpaceOrderedList("nowrap");
1379     }
1380 
1381     /**
1382      * Verifies getVisibleText().
1383      * @throws Exception if the test fails
1384      */
1385     @Test
1386     @Alerts("    first item\n      A B  C     D \nEF\nG \n H  \n I  \n"
1387                 + "    third item\n4. item\n    some text \n    \nlast item\n  ")
1388     public void getVisibleTextWhiteSpaceOrderedListPre() throws Exception {
1389         getVisibleTextWhiteSpaceOrderedList("pre");
1390     }
1391 
1392     /**
1393      * Verifies getVisibleText().
1394      * @throws Exception if the test fails
1395      */
1396     @Test
1397     @Alerts("    first item\n      A B  C     D \nEF\nG \n H  \n I  \n"
1398                 + "    third item\n4. item\n    some text \n    \nlast item\n  ")
1399     public void getVisibleTextWhiteSpaceOrderedListPreWrap() throws Exception {
1400         getVisibleTextWhiteSpaceOrderedList("pre-wrap");
1401     }
1402 
1403     /**
1404      * Verifies getVisibleText().
1405      * @throws Exception if the test fails
1406      */
1407     @Test
1408     @Alerts("first item\nA B C D \nEF\nG \n H\nI\nthird item\n4. item\nsome text\nlast item")
1409     @HtmlUnitNYI(CHROME = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1410             EDGE = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1411             FF = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1412             FF_ESR = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item")
1413     public void getVisibleTextWhiteSpaceOrderedListPreLine() throws Exception {
1414         getVisibleTextWhiteSpaceOrderedList("pre-line");
1415     }
1416 
1417     private void getVisibleTextWhiteSpaceOrderedList(final String whiteSpace) throws Exception {
1418         final String htmlContent = DOCTYPE_HTML
1419             + "<html>\n"
1420             + "<head></head>\n"
1421             + "<body>\n"
1422             + "  <ol id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1423             + "    <li>first item</li>\n"
1424             + "    <li>  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </li>\n"
1425             + "    <li>third item</li><li>4. item</li>\n"
1426             + "    some text \n"
1427             + "    <li>last item</li>\n"
1428             + "  </ol>\n"
1429             + "</body></html>";
1430 
1431         final WebDriver driver = loadPage2(htmlContent);
1432         final String text = driver.findElement(By.id("tester")).getText();
1433         assertEquals(getExpectedAlerts()[0], text);
1434 
1435         if (driver instanceof HtmlUnitDriver) {
1436             final HtmlPage page = (HtmlPage) getEnclosedPage();
1437             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1438             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1439         }
1440     }
1441 
1442     /**
1443      * Verifies getVisibleText().
1444      * @throws Exception if the test fails
1445      */
1446     @Test
1447     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1448     public void getVisibleTextWhiteSpaceUnorderedList() throws Exception {
1449         getVisibleTextWhiteSpaceUnorderedList(null);
1450     }
1451 
1452     /**
1453      * Verifies getVisibleText().
1454      * @throws Exception if the test fails
1455      */
1456     @Test
1457     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1458     public void getVisibleTextWhiteSpaceUnorderedListNormal() throws Exception {
1459         getVisibleTextWhiteSpaceUnorderedList("normal");
1460     }
1461 
1462     /**
1463      * Verifies getVisibleText().
1464      * @throws Exception if the test fails
1465      */
1466     @Test
1467     @Alerts("first item\nA B C D EF G H\nI\nthird item\n4. item\nsome text\nlast item")
1468     public void getVisibleTextWhiteSpaceUnorderedListNowrap() throws Exception {
1469         getVisibleTextWhiteSpaceUnorderedList("nowrap");
1470     }
1471 
1472     /**
1473      * Verifies getVisibleText().
1474      * @throws Exception if the test fails
1475      */
1476     @Test
1477     @Alerts("    first item\n      A B  C     D \nEF\nG \n H  \n I  \n"
1478                 + "    third item\n4. item\n    some text \n    \nlast item\n  ")
1479     public void getVisibleTextWhiteSpaceUnorderedListPre() throws Exception {
1480         getVisibleTextWhiteSpaceUnorderedList("pre");
1481     }
1482 
1483     /**
1484      * Verifies getVisibleText().
1485      * @throws Exception if the test fails
1486      */
1487     @Test
1488     @Alerts("    first item\n      A B  C     D \nEF\nG \n H  \n I  \n"
1489                 + "    third item\n4. item\n    some text \n    \nlast item\n  ")
1490     public void getVisibleTextWhiteSpaceUnorderedListPreWrap() throws Exception {
1491         getVisibleTextWhiteSpaceUnorderedList("pre-wrap");
1492     }
1493 
1494     /**
1495      * Verifies getVisibleText().
1496      * @throws Exception if the test fails
1497      */
1498     @Test
1499     @Alerts("first item\nA B C D \nEF\nG \n H\nI\nthird item\n4. item\nsome text\nlast item")
1500     @HtmlUnitNYI(CHROME = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1501             EDGE = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1502             FF = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item",
1503             FF_ESR = "first item\n A B C D \nEF\nG \n H\nI\n third item\n4. item\n some text \n\nlast item")
1504     public void getVisibleTextWhiteSpaceUnorderedListPreLine() throws Exception {
1505         getVisibleTextWhiteSpaceUnorderedList("pre-line");
1506     }
1507 
1508     private void getVisibleTextWhiteSpaceUnorderedList(final String whiteSpace) throws Exception {
1509         final String htmlContent = DOCTYPE_HTML
1510             + "<html>\n"
1511             + "<head></head>\n"
1512             + "<body>\n"
1513             + "  <ul id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1514             + "    <li>first item</li>\n"
1515             + "    <li>  A B  C\t \t  D \r\nEF\nG \n H  <br> I  </li>\n"
1516             + "    <li>third item</li><li>4. item</li>\n"
1517             + "    some text \n"
1518             + "    <li>last item</li>\n"
1519             + "  </ul>\n"
1520             + "</body></html>";
1521 
1522         final WebDriver driver = loadPage2(htmlContent);
1523         final String text = driver.findElement(By.id("tester")).getText();
1524         assertEquals(getExpectedAlerts()[0], text);
1525 
1526         if (driver instanceof HtmlUnitDriver) {
1527             final HtmlPage page = (HtmlPage) getEnclosedPage();
1528             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1529             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1530         }
1531     }
1532 
1533     /**
1534      * Verifies getVisibleText().
1535      * @throws Exception if the test fails
1536      */
1537     @Test
1538     @Alerts("The text to be tested")
1539     public void getVisibleTextLabel() throws Exception {
1540         getVisibleTextFormated("<label id='tester'>The text to be <span>tested</span></label>");
1541     }
1542 
1543     /**
1544      * Verifies getVisibleText().
1545      * @throws Exception if the test fails
1546      */
1547     @Test
1548     @Alerts("The text to be tested")
1549     public void getVisibleTextLabelNormal() throws Exception {
1550         getVisibleTextFormated("<label id='tester' style='white-space: normal'>"
1551                 + "The text to be <span>tested</span></label>");
1552     }
1553 
1554     /**
1555      * Verifies getVisibleText().
1556      * @throws Exception if the test fails
1557      */
1558     @Test
1559     @Alerts("The text to be tested")
1560     public void getVisibleTextLabelNowrap() throws Exception {
1561         getVisibleTextFormated("<label id='tester' style='white-space: nowrap'>"
1562                 + "The text to be <span>tested</span></label>");
1563     }
1564 
1565     /**
1566      * Verifies getVisibleText().
1567      * @throws Exception if the test fails
1568      */
1569     @Test
1570     @Alerts("The text to be tested")
1571     public void getVisibleTextLabelPre() throws Exception {
1572         getVisibleTextFormated("<label id='tester' style='white-space: pre'>"
1573                 + "The text to be <span>tested</span></label>");
1574     }
1575 
1576     /**
1577      * Verifies getVisibleText().
1578      * @throws Exception if the test fails
1579      */
1580     @Test
1581     @Alerts("The text to be tested")
1582     public void getVisibleTextLabelPreWrap() throws Exception {
1583         getVisibleTextFormated("<label id='tester' style='white-space: pre-wrap'>"
1584                 + "The text to be <span>tested</span></label>");
1585     }
1586 
1587     /**
1588      * Verifies getVisibleText().
1589      * @throws Exception if the test fails
1590      */
1591     @Test
1592     @Alerts("The text to be tested")
1593     public void getVisibleTextLabelPreLine() throws Exception {
1594         getVisibleTextFormated("<label id='tester' style='white-space: pre-line'>"
1595                 + "The text to be <span>tested</span></label>");
1596     }
1597 
1598     /**
1599      * Verifies getVisibleText().
1600      * @throws Exception if the test fails
1601      */
1602     @Test
1603     @Alerts("A   nbsp and spaces")
1604     public void getVisibleTextParagraphNbsp() throws Exception {
1605         getVisibleTextFormated("<p id='tester'>A &nbsp; nbsp and spaces</p>");
1606     }
1607 
1608     /**
1609      * Verifies getVisibleText().
1610      * @throws Exception if the test fails
1611      */
1612     @Test
1613     @Alerts("A   nbsp and spaces")
1614     public void getVisibleTextParagraphNbspNormal() throws Exception {
1615         getVisibleTextFormated("<p id='tester' style='white-space: normal'>"
1616                 + "A &nbsp; nbsp and spaces</p>");
1617     }
1618 
1619     /**
1620      * Verifies getVisibleText().
1621      * @throws Exception if the test fails
1622      */
1623     @Test
1624     @Alerts("A   nbsp and spaces")
1625     public void getVisibleTextParagraphNbspNowrap() throws Exception {
1626         getVisibleTextFormated("<p id='tester' style='white-space: nowrap'>"
1627                 + "A &nbsp; nbsp and spaces</p>");
1628     }
1629 
1630     /**
1631      * Verifies getVisibleText().
1632      * @throws Exception if the test fails
1633      */
1634     @Test
1635     @Alerts("A   nbsp and spaces")
1636     public void getVisibleTextParagraphNbspPre() throws Exception {
1637         getVisibleTextFormated("<p id='tester' style='white-space: pre'>"
1638                 + "A &nbsp; nbsp and spaces</p>");
1639     }
1640 
1641     /**
1642      * Verifies getVisibleText().
1643      * @throws Exception if the test fails
1644      */
1645     @Test
1646     @Alerts("A   nbsp and spaces")
1647     public void getVisibleTextParagraphNbspPreWrap() throws Exception {
1648         getVisibleTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1649                 + "A &nbsp; nbsp and spaces</p>");
1650     }
1651 
1652     /**
1653      * Verifies getVisibleText().
1654      * @throws Exception if the test fails
1655      */
1656     @Test
1657     @Alerts("A   nbsp and spaces")
1658     public void getVisibleTextParagraphNbspPreLine() throws Exception {
1659         getVisibleTextFormated("<p id='tester' style='white-space: pre-line'>"
1660                 + "A &nbsp; nbsp and spaces</p>");
1661     }
1662 
1663     /**
1664      * Verifies getVisibleText().
1665      * @throws Exception if the test fails
1666      */
1667     @Test
1668     @Alerts("A  \n  NBSPs  ")
1669     public void getVisibleTextParagraphMultilineNbsp() throws Exception {
1670         getVisibleTextFormated("<p id='tester'>A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1671     }
1672 
1673     /**
1674      * Verifies getVisibleText().
1675      * @throws Exception if the test fails
1676      */
1677     @Test
1678     @Alerts("A  \n  NBSPs  ")
1679     public void getVisibleTextParagraphMultilineNbspNormal() throws Exception {
1680         getVisibleTextFormated("<p id='tester' style='white-space: normal'>"
1681                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1682     }
1683 
1684     /**
1685      * Verifies getVisibleText().
1686      * @throws Exception if the test fails
1687      */
1688     @Test
1689     @Alerts("A  \n  NBSPs  ")
1690     public void getVisibleTextParagraphMultilineNbspNowrap() throws Exception {
1691         getVisibleTextFormated("<p id='tester' style='white-space: nowrap'>"
1692                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1693     }
1694 
1695     /**
1696      * Verifies getVisibleText().
1697      * @throws Exception if the test fails
1698      */
1699     @Test
1700     @Alerts("A  \n  NBSPs  ")
1701     public void getVisibleTextParagraphMultilineNbspPre() throws Exception {
1702         getVisibleTextFormated("<p id='tester' style='white-space: pre'>"
1703                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1704     }
1705 
1706     /**
1707      * Verifies getVisibleText().
1708      * @throws Exception if the test fails
1709      */
1710     @Test
1711     @Alerts("A  \n  NBSPs  ")
1712     public void getVisibleTextParagraphMultilineNbspPreWrap() throws Exception {
1713         getVisibleTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1714                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1715     }
1716 
1717     /**
1718      * Verifies getVisibleText().
1719      * @throws Exception if the test fails
1720      */
1721     @Test
1722     @Alerts("A  \n  NBSPs  ")
1723     public void getVisibleTextParagraphMultilineNbspPreLine() throws Exception {
1724         getVisibleTextFormated("<p id='tester' style='white-space: pre-line'>"
1725                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1726     }
1727 
1728     /**
1729      * Verifies getVisibleText() for issue #128
1730      * (https://github.com/HtmlUnit/htmlunit/issues/128).
1731      * @throws Exception if the test fails
1732      */
1733     @Test
1734     @Alerts("I have out of 2 stamps")
1735     public void getVisibleTextInputInsideP() throws Exception {
1736         getVisibleTextFormated("<p id='tester'>"
1737                 + " I have <input type='number' value='2'/> out of 2 stamps</p>");
1738     }
1739 
1740     /**
1741      * @throws Exception if the test fails
1742      */
1743     @Test
1744     @Alerts("Sum")
1745     public void getVisibleTextDetails() throws Exception {
1746         getVisibleTextFormated("<details id='tester'>"
1747                 + "<summary>Sum</summary>"
1748                 + "<p>detail</p>"
1749                 + "</details>");
1750     }
1751 
1752     /**
1753      * @throws Exception if the test fails
1754      */
1755     @Test
1756     @Alerts("Sum\nSum2")
1757     public void getVisibleTextDetailsTwoSums() throws Exception {
1758         getVisibleTextFormated("<details id='tester'>"
1759                 + "<summary>Sum</summary>"
1760                 + "<summary>Sum2</summary>"
1761                 + "<p>detail</p>"
1762                 + "</details>");
1763     }
1764 
1765     /**
1766      * @throws Exception if the test fails
1767      */
1768     @Test
1769     @Alerts("Sum\ndetail")
1770     public void getVisibleTextDetailsOpen() throws Exception {
1771         getVisibleTextFormated("<details id='tester' open=true>"
1772                 + "<summary>Sum</summary>"
1773                 + "<p>detail</p>"
1774                 + "</details>");
1775     }
1776 
1777 
1778     /**
1779      * @throws Exception if the test fails
1780      */
1781     @Test
1782     @Alerts("beforeafter")
1783     public void getVisibleTextCdata() throws Exception {
1784         getVisibleTextFormated("<div id='tester'>"
1785                 + "before<![CDATA[inside]]>after"
1786                 + "</div>");
1787     }
1788 
1789     private void getVisibleTextFormated(final String htmlTesterSnipped) throws Exception {
1790         final String htmlContent = DOCTYPE_HTML
1791             + "<html>\n"
1792             + "<head></head>\n"
1793             + "<body>\n"
1794             + "  " + htmlTesterSnipped + "\n"
1795             + "</body></html>";
1796 
1797         final WebDriver driver = loadPage2(htmlContent);
1798         final String text = driver.findElement(By.id("tester")).getText();
1799         assertEquals(getExpectedAlerts()[0], text);
1800 
1801         if (driver instanceof HtmlUnitDriver) {
1802             final HtmlPage page = (HtmlPage) getEnclosedPage();
1803             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1804             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1805         }
1806     }
1807 
1808     /**
1809      * @throws Exception if the test fails
1810      */
1811     @Test
1812     @Alerts("xy")
1813     public void getVisibleNumberInputValidNumber() throws Exception {
1814         getVisibleTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "12");
1815     }
1816 
1817     /**
1818      * @throws Exception if the test fails
1819      */
1820     @Test
1821     @Alerts("xy")
1822     public void getVisibleNumberInputInvalidNumber() throws Exception {
1823         getVisibleTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "ab");
1824     }
1825 
1826     /**
1827      * @throws Exception if the test fails
1828      */
1829     @Test
1830     @Alerts("demo")
1831     public void getVisibleEm() throws Exception {
1832         getVisibleTextFormated("<em id='tester'>demo</em>");
1833     }
1834 
1835     private void getVisibleTextFormatedAfterTyping(final String htmlTesterSnipped,
1836                         final String... typed) throws Exception {
1837         final String htmlContent = DOCTYPE_HTML
1838             + "<html>\n"
1839             + "<head></head>\n"
1840             + "<body>\n"
1841             + "  " + htmlTesterSnipped + "\n"
1842             + "</body></html>";
1843 
1844         final WebDriver driver = loadPage2(htmlContent);
1845 
1846         final WebElement input = driver.findElement(By.id("inpt"));
1847         for (final String string : typed) {
1848             input.sendKeys(string);
1849         }
1850 
1851         final String text = driver.findElement(By.id("tester")).getText();
1852         assertEquals(getExpectedAlerts()[0], text);
1853 
1854         if (driver instanceof HtmlUnitDriver) {
1855             final HtmlPage page = (HtmlPage) getEnclosedPage();
1856             assertEquals(getExpectedAlerts()[0], page.getElementById("tester").getVisibleText());
1857             assertEquals(getExpectedAlerts()[0], page.getVisibleText());
1858         }
1859     }
1860 }