private String getSelectOptionLabelForValue(HtmlSelect sel, String value) { for (HtmlOption opt : sel.getOptions()) { if (opt.getValueAttribute().equals(value)) { return opt.asText(); } } throw new RuntimeException("Unable to find option " + value + " for " + sel.getNameAttribute()); }
private String getSelectOptionValueForLabel(HtmlSelect sel, String label) { for (HtmlOption opt : sel.getOptions()) { if (opt.asText().equals(label)) { return opt.getValueAttribute(); } } throw new RuntimeException("Unable to find option " + label + " for " + sel.getNameAttribute()); }
/** * Returns a text representation of this element that represents what would * be visible to the user if this page was shown in a web browser. If the user * can only select one option at a time, this method returns the selected option. * If the user can select multiple options, this method returns all options. * * @return the element as text */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { final List<HtmlOption> options; if (isMultipleSelectEnabled()) { options = getOptions(); } else { options = getSelectedOptions(); } final StringBuilder builder = new StringBuilder(); for (final Iterator<HtmlOption> i = options.iterator(); i.hasNext();) { final HtmlOption currentOption = i.next(); if (currentOption != null) { builder.append(currentOption.asText()); } if (i.hasNext()) { builder.append('\n'); } } return builder.toString(); }
/** * Returns a text representation of this element that represents what would * be visible to the user if this page was shown in a web browser. If the user * can only select one option at a time, this method returns the selected option. * If the user can select multiple options, this method returns all options. * * @return the element as text */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { final List<HtmlOption> options; if (isMultipleSelectEnabled()) { options = getOptions(); } else { options = getSelectedOptions(); } final StringBuilder builder = new StringBuilder(); for (final Iterator<HtmlOption> i = options.iterator(); i.hasNext();) { final HtmlOption currentOption = i.next(); if (currentOption != null) { builder.append(currentOption.asText()); } if (i.hasNext()) { builder.append("\n"); } } return builder.toString(); }
/** * Returns a text representation of this element that represents what would * be visible to the user if this page was shown in a web browser. If the user * can only select one option at a time, this method returns the selected option. * If the user can select multiple options, this method returns all options. * * @return the element as text */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { final List<HtmlOption> options; if (isMultipleSelectEnabled()) { options = getOptions(); } else { options = getSelectedOptions(); } final StringBuilder buffer = new StringBuilder(); for (final Iterator<HtmlOption> i = options.iterator(); i.hasNext();) { final HtmlOption currentOption = i.next(); if (currentOption != null) { buffer.append(currentOption.asText()); } if (i.hasNext()) { buffer.append("\n"); } } return buffer.toString(); }
/** * Returns a text representation of this element that represents what would * be visible to the user if this page was shown in a web browser. If the user * can only select one option at a time, this method returns the selected option. * If the user can select multiple options, this method returns all options. * * @return the element as text */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { final List<HtmlOption> options; if (isMultipleSelectEnabled()) { options = getOptions(); } else { options = getSelectedOptions(); } final StringBuilder buffer = new StringBuilder(); for (final Iterator<HtmlOption> i = options.iterator(); i.hasNext();) { final HtmlOption currentOption = i.next(); if (currentOption != null) { buffer.append(currentOption.asText()); } if (i.hasNext()) { buffer.append("\n"); } } return buffer.toString(); }
/** * Returns a text representation of this element that represents what would * be visible to the user if this page was shown in a web browser. If the user * can only select one option at a time, this method returns the selected option. * If the user can select multiple options, this method returns all options. * * @return the element as text */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { final List<HtmlOption> options; if (isMultipleSelectEnabled()) { options = getOptions(); } else { options = getSelectedOptions(); } final StringBuilder buffer = new StringBuilder(); for (final Iterator<HtmlOption> i = options.iterator(); i.hasNext();) { final HtmlOption currentOption = i.next(); if (currentOption != null) { buffer.append(currentOption.asText()); } if (i.hasNext()) { buffer.append("\n"); } } return buffer.toString(); }
@Override public void unselectOptions(String selectName, int index, String[] options) { List<HtmlSelect> sels = getForm().getSelectsByName(selectName); if (sels == null || sels.size() < index + 1) { throw new RuntimeException("Did not find select with name [" + selectName + "] at index " + index); } HtmlSelect sel = sels.get(index); if (!sel.isMultipleSelectEnabled() && options.length > 1) { throw new RuntimeException("Multiselect not enabled"); } for (String option : options) { boolean found = false; for (HtmlOption opt : sel.getOptions()) { if (opt.asText().equals(option)) { sel.setSelectedAttribute(opt, false); found = true; break; } } if (!found) { throw new RuntimeException("Option " + option + " not found"); } } }
@Override public void unselectOptions(String selectName, String[] options) { HtmlSelect sel = getForm().getSelectByName(selectName); if (!sel.isMultipleSelectEnabled() && options.length > 1) { throw new RuntimeException("Multiselect not enabled"); } for (String option : options) { boolean found = false; for (HtmlOption opt : sel.getOptions()) { if (opt.asText().equals(option)) { sel.setSelectedAttribute(opt, false); found = true; break; } } if (!found) { throw new RuntimeException("Option " + option + " not found"); } } }