MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / replaceOption

Method replaceOption

src/main/java/org/htmlunit/html/HtmlSelect.java:216–234  ·  view source on GitHub ↗

Replace an option at the given index with a new option. @param index the index of the option to remove @param newOption the new option to replace to indexed option

(final int index, final HtmlOption newOption)

Source from the content-addressed store, hash-verified

214 * @param newOption the new option to replace to indexed option
215 */
216 public void replaceOption(final int index, final HtmlOption newOption) {
217 final ChildElementsIterator iterator = new ChildElementsIterator(this);
218 int i = 0;
219 while (iterator.hasNext()) {
220 final DomElement element = iterator.next();
221 if (element instanceof HtmlOption) {
222 if (i == index) {
223 element.replace(newOption);
224 ensureSelectedIndex();
225 return;
226 }
227 i++;
228 }
229 }
230
231 if (newOption.isSelected()) {
232 setSelectedAttribute(newOption, true);
233 }
234 }
235
236 /**
237 * Add a new option at the end.

Callers 1

putMethod · 0.80

Calls 6

hasNextMethod · 0.95
nextMethod · 0.95
ensureSelectedIndexMethod · 0.95
setSelectedAttributeMethod · 0.95
replaceMethod · 0.45
isSelectedMethod · 0.45

Tested by

no test coverage detected