KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > html > HtmlSelectTest


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit.html;
39
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collections;
43 import java.util.List;
44
45 import com.gargoylesoftware.htmlunit.KeyValuePair;
46 import com.gargoylesoftware.htmlunit.MockWebConnection;
47 import com.gargoylesoftware.htmlunit.SubmitMethod;
48 import com.gargoylesoftware.htmlunit.WebTestCase;
49
50 /**
51  * Tests for HtmlSelect
52  *
53  * @version $Revision: 1.16 $
54  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
55  * @author Mike Williams
56  */

57 public class HtmlSelectTest extends WebTestCase {
58
59     /**
60      * Create an instance
61      *
62      * @param name Name of the test
63      */

64     public HtmlSelectTest(final String name) {
65         super(name);
66     }
67
68     /**
69      * Test the good path of submitting a select
70      *
71      * @exception Exception If the test fails
72      */

73     public void testSelect() throws Exception {
74
75         final String htmlContent = "<html><head><title>foo</title></head><body>"
76             + "<form id='form1'><select name='select1'>"
77             + "<option value='option1'>Option1</option>"
78             + "<option value='option2' selected='selected'>Option2</option>"
79             + "<option value='option3'>Option3</option>"
80             + "</select>"
81             + "<input type='submit' name='button' value='foo'/>"
82             + "</form></body></html>";
83         final HtmlPage page = loadPage(htmlContent);
84         final MockWebConnection webConnection = getMockConnection(page);
85
86         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
87
88         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
89         final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("button");
90
91         // Test that the select is being correctly identified as a submittable element
92
assertCollectionsEqual(Arrays.asList(new Object[] {select, button}), form.getAllSubmittableElements(button));
93
94         // Test that the correct value is being passed back up to the server
95
final HtmlPage secondPage = (HtmlPage) button.click();
96
97         final List expectedParameters = new ArrayList();
98         expectedParameters.add(new KeyValuePair("select1", "option2"));
99         expectedParameters.add(new KeyValuePair("button", "foo"));
100
101         assertEquals("url", URL_GARGOYLE, secondPage.getWebResponse().getUrl());
102         assertEquals("method", SubmitMethod.GET, webConnection.getLastMethod());
103         assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
104         assertNotNull(secondPage);
105     }
106
107     /**
108      * Test submitting the select with no options selected
109      *
110      * @exception Exception If the test fails
111      */

112     public void testSelect_MultipleSelectNoneSelected() throws Exception {
113
114         final String htmlContent = "<html><head><title>foo</title></head><body>"
115             + "<form id='form1'><select name='select1' multiple>"
116             + "<option value='option1'>Option1</option>"
117             + "<option value='option2'>Option2</option>"
118             + "<option value='option3'>Option3</option>"
119             + "</select>"
120             + "<input type='submit' name='button' value='foo'/>"
121             + "</form></body></html>";
122         final HtmlPage page = loadPage(htmlContent);
123         final MockWebConnection webConnection = getMockConnection(page);
124
125         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
126
127         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
128         assertNotNull(select);
129
130         final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("button");
131
132         // Test that the correct value is being passed back up to the server
133
final HtmlPage secondPage = (HtmlPage) button.click();
134
135         final List expectedParameters = new ArrayList();
136         expectedParameters.add(new KeyValuePair("button", "foo"));
137
138         assertEquals("url", URL_GARGOYLE, secondPage.getWebResponse().getUrl());
139         assertEquals("method", SubmitMethod.GET, webConnection.getLastMethod());
140         assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
141         assertNotNull(secondPage);
142     }
143
144     /**
145      * Test changing the selected option
146      *
147      * @exception Exception If the test fails
148      */

149     public void testSelect_ChangeSelectedOption_SingleSelect() throws Exception {
150
151         final String htmlContent = "<html><head><title>foo</title></head><body>"
152             + "<form id='form1'><select name='select1'>"
153             + "<option value='option1' selected='selected'>Option1</option>"
154             + "<option value='option2'>Option2</option>"
155             + "<option value='option3'>Option3</option>"
156             + "</select>"
157             + "<input type='submit' name='button' value='foo'/>"
158             + "</form></body></html>";
159         final HtmlPage page = loadPage(htmlContent);
160         final MockWebConnection webConnection = getMockConnection(page);
161
162         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
163
164         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
165         final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("button");
166
167         // Change the value
168
select.setSelectedAttribute("option3", true);
169
170         // Test that the correct value is being passed back up to the server
171
final HtmlPage secondPage = (HtmlPage) button.click();
172
173         final List expectedParameters = new ArrayList();
174         expectedParameters.add(new KeyValuePair("select1", "option3"));
175         expectedParameters.add(new KeyValuePair("button", "foo"));
176
177         assertEquals("url", URL_GARGOYLE, secondPage.getWebResponse().getUrl());
178         assertEquals("method", SubmitMethod.GET, webConnection.getLastMethod());
179         assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
180         assertNotNull(secondPage);
181     }
182
183     /**
184      * Test changing the selected option
185      *
186      * @exception Exception If the test fails
187      */

188     public void testSelect_ChangeSelectedOption_MultipleSelect() throws Exception {
189
190         final String htmlContent = "<html><head><title>foo</title></head><body>"
191             + "<form id='form1'><select name='select1' multiple='multiple'>"
192             + "<option value='option1' selected='selected'>Option1</option>"
193             + "<option value='option2'>Option2</option>"
194             + "<option value='option3'>Option3</option>"
195             + "</select>"
196             + "<input type='submit' name='button' value='foo'/>"
197             + "</form></body></html>";
198         final HtmlPage page = loadPage(htmlContent);
199         final MockWebConnection webConnection = getMockConnection(page);
200
201         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
202
203         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
204         final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("button");
205
206         // Change the value
207
select.setSelectedAttribute("option3", true);
208         select.setSelectedAttribute("option2", true);
209
210         // Test that the correct value is being passed back up to the server
211
final HtmlPage secondPage = (HtmlPage) button.click();
212
213         final List expectedParameters = new ArrayList();
214         expectedParameters.add(new KeyValuePair("select1", "option1"));
215         expectedParameters.add(new KeyValuePair("select1", "option2"));
216         expectedParameters.add(new KeyValuePair("select1", "option3"));
217         expectedParameters.add(new KeyValuePair("button", "foo"));
218
219         assertEquals("url", URL_GARGOYLE, secondPage.getWebResponse().getUrl());
220         assertEquals("method", SubmitMethod.GET, webConnection.getLastMethod());
221         assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
222         assertNotNull(secondPage);
223     }
224
225     /**
226      * Test multiple selected options on multiple select lists
227      *
228      * @exception Exception If the test fails
229      */

230     public void testSelect_MultipleSelectMultipleSelected() throws Exception {
231
232         final String htmlContent = "<html><head><title>foo</title></head><body>"
233             + "<form id='form1'><select name='select1' multiple>"
234             + "<option value='option1' selected='selected'>Option1</option>"
235             + "<option value='option2'>Option2</option>"
236             + "<option value='option3' selected='selected'>Option3</option>"
237             + "</select>"
238             + "<input type='submit' name='button' value='foo'/>"
239             + "</form></body></html>";
240         final HtmlPage page = loadPage(htmlContent);
241
242         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
243
244         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
245         final List expected = new ArrayList();
246         expected.add(select.getOptionByValue("option1"));
247         expected.add(select.getOptionByValue("option3"));
248
249         assertEquals(expected, select.getSelectedOptions());
250     }
251
252     /**
253      * Test multiple selected options on single select lists. This is erroneous HTML, but
254      * browsers simply use the last option.
255      *
256      * @exception Exception If the test fails
257      */

258     public void testSelect_SingleSelectMultipleSelected() throws Exception {
259
260         final String htmlContent = "<html><head><title>foo</title></head><body>"
261             + "<form id='form1'><select name='select1'>"
262             + "<option value='option1' selected='selected'>Option1</option>"
263             + "<option value='option2'>Option2</option>"
264             + "<option value='option3' selected='selected'>Option3</option>"
265             + "</select>"
266             + "<input type='submit' name='button' value='foo'/>"
267             + "</form></body></html>";
268         final HtmlPage page = loadPage(htmlContent);
269
270         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
271
272         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
273         final List expected = new ArrayList();
274         expected.add(select.getOptionByValue("option3"));
275
276         assertEquals(expected, select.getSelectedOptions());
277     }
278
279     /**
280      * Test no selected options on single select lists. This is erroneous HTML, but
281      * browsers simply assume the first one to be selected
282      *
283      * @exception Exception If the test fails
284      */

285     public void testSelect_SingleSelectNoneSelected() throws Exception {
286
287         final String htmlContent = "<html><head><title>foo</title></head><body>"
288             + "<form id='form1'><select name='select1'>"
289             + "<option value='option1'>Option1</option>"
290             + "<option value='option2'>Option2</option>"
291             + "<option value='option3'>Option3</option>"
292             + "</select>"
293             + "<input type='submit' name='button' value='foo'/>"
294             + "</form></body></html>";
295         final HtmlPage page = loadPage(htmlContent);
296
297         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
298
299         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
300         final List expected = new ArrayList();
301         expected.add(select.getOptionByValue("option1"));
302
303         assertEquals(expected, select.getSelectedOptions());
304     }
305
306     /**
307      * Test no selected options on single select lists with a size > 1
308      *
309      * @exception Exception If the test fails
310      */

311     public void testSelect_SingleSelectNoneSelectedButSizeGreaterThanOne() throws Exception {
312
313         final String htmlContent = "<html><head><title>foo</title></head><body>"
314             + "<form>"
315             + "<select name='select1' size='2' id='mySelect'>"
316             + "<option value='option1'>Option1</option>"
317             + "<option value='option2'>Option2</option>"
318             + "<option value='option3'>Option3</option>"
319             + "</select>"
320             + "</form></body></html>";
321
322         final HtmlPage page = loadPage(htmlContent);
323
324         final HtmlSelect select = (HtmlSelect) page.getHtmlElementById("mySelect");
325
326         assertEquals(Collections.EMPTY_LIST, select.getSelectedOptions());
327     }
328
329     /**
330      * Test changing the selected option
331      *
332      * @exception Exception If the test fails
333      */

334     public void testSetSelected_IllegalValue() throws Exception {
335
336         final String htmlContent = "<html><head><title>foo</title></head><body>"
337             + "<form id='form1'><select name='select1'>"
338             + "<option value='option1' selected='selected'>Option1</option>"
339             + "<option value='option2'>Option2</option>"
340             + "<option value='option3'>Option3</option>"
341             + "</select>"
342             + "<input type='submit' name='button' value='foo'/>"
343             + "</form></body></html>";
344         final HtmlPage page = loadPage(htmlContent);
345         final MockWebConnection webConnection = getMockConnection(page);
346
347         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
348
349         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
350         final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputByName("button");
351
352         // Change the value
353
try {
354             select.setSelectedAttribute("missingOption", true);
355             fail("Expected IllegalArgumentException");
356         }
357         catch (final IllegalArgumentException e) {
358             // Expected path
359
}
360
361         select.fakeSelectedAttribute("newOption");
362
363         // Test that the correct value is being passed back up to the server
364
final HtmlPage secondPage = (HtmlPage) button.click();
365
366         final List expectedParameters = new ArrayList();
367         expectedParameters.add(new KeyValuePair("select1", "newOption"));
368         expectedParameters.add(new KeyValuePair("button", "foo"));
369
370         assertEquals("url", URL_GARGOYLE, secondPage.getWebResponse().getUrl());
371         assertEquals("method", SubmitMethod.GET, webConnection.getLastMethod());
372         assertEquals("parameters", expectedParameters, webConnection.getLastParameters());
373         assertNotNull(secondPage);
374     }
375
376     /**
377      * @throws Exception if the test fails
378      */

379     public void testGetAllOptions() throws Exception {
380
381         final String htmlContent = "<html><head><title>foo</title></head><body>"
382             + "<form id='form1'><select name='select1'>"
383             + "<option value='option1' selected='selected'>Option1</option>"
384             + "<option value='option2'>Option2</option>"
385             + "<optgroup label='group1'>"
386             + " <option value='option3'>Option3</option>"
387             + "</optgroup>"
388             + "</select>"
389             + "<input type='submit' name='button' value='foo'/>"
390             + "</form></body></html>";
391         final HtmlPage page = loadPage(htmlContent);
392
393         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
394
395         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
396
397         final List expectedOptions = new ArrayList();
398         expectedOptions.add(select.getOptionByValue("option1"));
399         expectedOptions.add(select.getOptionByValue("option2"));
400         expectedOptions.add(select.getOptionByValue("option3"));
401
402         assertEquals(expectedOptions, select.getAllOptions());
403     }
404
405     /**
406      * @throws Exception if the test fails
407      */

408     public void testSelect_OptionMultiple_NoValueOnAttribute() throws Exception {
409
410         final String htmlContent = "<html><head><title>foo</title></head><body>"
411             + "<form id='form1'><select name='select1' id='select1' multiple>"
412             + "<option value='option1'>Option1</option>"
413             + "<option value='option2' >Option2</option>"
414             + "<option value='option3'>Option3</option>"
415             + "</select>"
416             + "<input type='submit' name='button' value='foo'/>"
417             + "</form></body></html>";
418         final HtmlPage page = loadPage(htmlContent);
419
420         final HtmlSelect select = (HtmlSelect) page.getHtmlElementById("select1");
421         assertTrue(select.isMultipleSelectEnabled());
422     }
423
424     /**
425      * @throws Exception if the test fails
426      */

427     public void testGetOptionByValue_TwoOptionsWithSameValue() throws Exception {
428
429         final String htmlContent = "<html><head><title>foo</title></head><body><form id='form1'>"
430             + "<select name='select1'>"
431             + " <option value='option1'>s1o1</option>"
432             + " <option value='option2'>s1o2</option>"
433             + "</select>"
434             + "<select name='select2'>"
435             + " <option value='option1'>s2o1</option>"
436             + " <option value='option2'>s2o2</option>"
437             + "</select>"
438             + "<input type='submit' name='button' value='foo'/>"
439             + "</form></body></html>";
440         final HtmlPage page = loadPage(htmlContent);
441
442         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
443
444         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select2").get(0);
445         assertEquals("s2o2", select.getOptionByValue("option2").asText());
446     }
447
448     /**
449      * @throws Exception if the test fails
450      */

451     public void testSelect_SetSelected_OnChangeHandler() throws Exception {
452
453         final String htmlContent = "<html><head><title>foo</title></head><body>"
454             + "<form id='form1'><select name='select1' onChange='alert(\"changing\")'>"
455             + "<option value='option1' selected='selected'>Option1</option>"
456             + "<option value='option2'>Option2</option>"
457             + "<option value='option3'>Option3</option>"
458             + "</select>"
459             + "<input type='submit' name='button' value='foo'/>"
460             + "</form></body></html>";
461         final List collectedAlerts = new ArrayList();
462         final HtmlPage page = loadPage(htmlContent, collectedAlerts);
463
464         final HtmlForm form = (HtmlForm) page.getHtmlElementById("form1");
465
466         final HtmlSelect select = (HtmlSelect) form.getSelectsByName("select1").get(0);
467
468         // Change the value
469
select.setSelectedAttribute("option3", true);
470
471         final List expectedAlerts = Collections.singletonList("changing");
472         assertEquals(expectedAlerts, collectedAlerts);
473     }
474
475     /**
476      * @throws Exception if the test fails
477      */

478     public void testSetSelectionOnOptionWithNoName() throws Exception {
479
480         final String htmlContent = "<html><body><form name='form' method='GET' action='action.html'>"
481             + "<select name='select' multiple size='5'>"
482             + "<option value='1'>111</option>"
483             + "<option id='option2'>222</option>"
484             + "</select>"
485             + "</form></body></html>";
486         final List collectedAlerts = new ArrayList();
487         final HtmlPage page = loadPage(htmlContent, collectedAlerts);
488
489         final HtmlOption option = (HtmlOption) page.getHtmlElementById("option2");
490         option.setSelected(true);
491     }
492
493     private void checkOptions(final HtmlSelect select) {
494         final List options = select.getAllOptions();
495         if (options.isEmpty()) {
496             assertNull(select.getFirstChild());
497             assertNull(select.getLastChild());
498         }
499         else {
500             assertEquals(options.get(0), select.getFirstChild());
501             assertEquals(options.get(options.size() - 1), select.getLastChild());
502         }
503     }
504
505     /** @throws Exception if the test fails */
506     public void testRemoveOptionsFromSelect() throws Exception {
507
508         final String htmlContent = "<html><body><form name='form' method='GET' action='action.html'>"
509             + "<select name='select' id='theSelect'>"
510             + "<option value='a'>111</option>"
511             + "<option value='b'>222</option>"
512             + "<option value='c'>333</option>"
513             + "<option value='d'>444</option>"
514             + "</select>"
515             + "</form></body></html>";
516         final HtmlPage page = loadPage(htmlContent);
517
518         final HtmlSelect theSelect = (HtmlSelect) page.getHtmlElementById("theSelect");
519         assertNotNull(theSelect);
520
521         assertEquals(4, theSelect.getAllOptions().size());
522         assertEquals("a", theSelect.getOption(0).getValue());
523         assertEquals("b", theSelect.getOption(1).getValue());
524         assertEquals("c", theSelect.getOption(2).getValue());
525         assertEquals("d", theSelect.getOption(3).getValue());
526
527         // remove from the middle
528
theSelect.getOption(1).remove();
529         checkOptions(theSelect);
530         assertEquals(3, theSelect.getAllOptions().size());
531         assertEquals("a", theSelect.getOption(0).getValue());
532         assertEquals("c", theSelect.getOption(1).getValue());
533         assertEquals("d", theSelect.getOption(2).getValue());
534
535         // remove from the end
536
theSelect.getOption(2).remove();
537         checkOptions(theSelect);
538         assertEquals(2, theSelect.getAllOptions().size());
539         assertEquals("a", theSelect.getOption(0).getValue());
540         assertEquals("c", theSelect.getOption(1).getValue());
541
542         // remove from the front
543
theSelect.getOption(0).remove();
544         checkOptions(theSelect);
545         assertEquals(1, theSelect.getAllOptions().size());
546         assertEquals("c", theSelect.getOption(0).getValue());
547
548         // remove from the last one
549
theSelect.getOption(0).remove();
550         checkOptions(theSelect);
551         assertEquals(0, theSelect.getAllOptions().size());
552     }
553
554     /** @throws Exception If the test fails */
555     public void testEditOptions() throws Exception {
556
557         final String htmlContent = "<html><body><form name='form' method='GET' action='action.html'>"
558             + "<select name='select' id='theSelect'>"
559             + "<option value='a'>111</option>"
560             + "<option value='b'>222</option>"
561             + "<option value='c'>333</option>"
562             + "</select>"
563             + "</form></body></html>";
564         final HtmlPage page = loadPage(htmlContent);
565
566         final HtmlSelect theSelect = (HtmlSelect) page.getHtmlElementById("theSelect");
567
568         assertNotNull(theSelect);
569         assertEquals(3, theSelect.getAllOptions().size());
570
571         appendOption(theSelect, "d");
572         assertEquals(4, theSelect.getAllOptions().size());
573         assertEquals("d", theSelect.getOption(3).getValue());
574
575         theSelect.setOptionSize(1);
576         assertEquals(1, theSelect.getAllOptions().size());
577         assertEquals("a", theSelect.getOption(0).getValue());
578
579         appendOption(theSelect, "x");
580         assertEquals(2, theSelect.getAllOptions().size());
581         assertEquals("x", theSelect.getOption(1).getValue());
582
583     }
584
585     /**
586      * Test that asText() returns a blank string if nothing is selected.
587      *
588      * @exception Exception If the test fails
589      */

590     public void testAsTextWhenNothingSelected() throws Exception {
591         final String htmlContent = "<html><head><title>foo</title></head><body>"
592             + "<form>"
593             + "<select name='select1' size='1' id='mySelect'>"
594             + "</select>"
595             + "</form></body></html>";
596
597         final HtmlPage page = loadPage(htmlContent);
598
599         final HtmlSelect select = (HtmlSelect) page.getHtmlElementById("mySelect");
600
601         assertEquals("", select.asText());
602     }
603
604     void appendOption(final HtmlSelect select, final String value) {
605         final HtmlOption option = new HtmlOption(select.getPage(), null);
606         option.setValueAttribute(value);
607         option.setLabelAttribute(value);
608         select.appendOption(option);
609     }
610
611 }
612
Popular Tags