Skip to content

Commit ead1db2

Browse files
committed
more unit tests (using #137 as inspiration)
1 parent fbc2bca commit ead1db2

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/test/java/org/openqa/selenium/htmlunit/HtmlUnitWebElementAttributeTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,58 @@ public void valueOption() throws Exception {
114114
assertEquals("4", elem.getAttribute("value"));
115115
}
116116

117+
@Test
118+
public void indexOption() throws Exception {
119+
final String html = "<html>\n"
120+
+ "<head>\n"
121+
+ "</head>\n"
122+
+ "<body>\n"
123+
+ "<form>\n"
124+
+ " <select id='selectWithRandomMultipleValue' multiple='somethingElse'>\n"
125+
+ " <option id='o1' value='one'>option one</option>\n"
126+
+ " <option id='o2'>option two</option>\n"
127+
+ " <option id='o3'>option three \n second line</option>\n"
128+
+ " <option id='o4' value='4'>option four</option>\n"
129+
+ " </select>\n"
130+
+ "</form>\n"
131+
+ "</body>\n"
132+
+ "</html>\n";
133+
134+
final WebDriver driver = loadPage2(html);
135+
136+
WebElement elem = driver.findElement(By.id("o1"));
137+
assertEquals("0", elem.getAttribute("index"));
138+
139+
elem = driver.findElement(By.id("o2"));
140+
assertEquals("1", elem.getAttribute("index"));
141+
142+
elem = driver.findElement(By.id("o3"));
143+
assertEquals("2", elem.getAttribute("index"));
144+
145+
elem = driver.findElement(By.id("o4"));
146+
assertEquals("3", elem.getAttribute("index"));
147+
}
148+
149+
@Test
150+
public void indexP() throws Exception {
151+
final String html = "<html>\n"
152+
+ "<head>\n"
153+
+ "</head>\n"
154+
+ "<body>\n"
155+
+ " <p id='d1'>1</p>\n"
156+
+ " <p id='d2' index='two'>2</p>\n"
157+
+ "</body>\n"
158+
+ "</html>\n";
159+
160+
final WebDriver driver = loadPage2(html);
161+
162+
WebElement elem = driver.findElement(By.id("d1"));
163+
assertNull(elem.getAttribute("index"));
164+
165+
elem = driver.findElement(By.id("d2"));
166+
assertEquals("two", elem.getAttribute("index"));
167+
}
168+
117169
@Test
118170
public void valueDiv() throws Exception {
119171
final String html = "<html>\n"

0 commit comments

Comments
 (0)