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