WebClient client = ... Page page = client.getPage(url); HtmlSelect select = (HtmlSelect) page.getElementById(mySelectId); HtmlOption option = select.getOptionByValue(desiredOptionValue); select.setSelectedAttribute(option, true);
/** * {@inheritDoc} * @see SubmittableElement#setDefaultValue(String) */ @Override public void setDefaultValue(final String defaultValue) { setSelectedAttribute(defaultValue, true); }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultValue(String) */ public void setDefaultValue(final String defaultValue) { setSelectedAttribute(defaultValue, true); }
final HtmlSelect text_nazione = form.getSelectByName("nazione"); text_nazione.setSelectedAttribute("italy", true); // now onchange event triggered and round-trip to server wc.waitForBackgroundJavaScript(3000); currentPage= (HtmlPage) wc.getCurrentWindow().getEnclosedPage(); form = currentPage.getFormByName("_form"); final HtmlSelect text_regione= form.getSelectByName("regione"); text_regione.setSelectedAttribute("I2", true); tmlButtonInput button = form.getElementById("invia"); currentPage = (HtmlPage) button.click();
/** * {@inheritDoc} * @see SubmittableElement#setDefaultValue(String) */ public void setDefaultValue(final String defaultValue) { setSelectedAttribute(defaultValue, true); }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultValue(String) */ @Override public void setDefaultValue(final String defaultValue) { setSelectedAttribute(defaultValue, true); }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultValue(String) */ public void setDefaultValue(final String defaultValue) { setSelectedAttribute(defaultValue, true); }
/** * Sets the "selected" state of the specified option. If this "select" element * is single-select, then calling this method will deselect all other options. * * Only options that are actually in the document may be selected. * * @param isSelected true if the option is to become selected * @param selectedOption the value of the option that is to change * @param <P> the page type * @return the page contained in the current window as returned * by {@link com.gargoylesoftware.htmlunit.WebClient#getCurrentWindow()} */ @SuppressWarnings("unchecked") public <P extends Page> P setSelectedAttribute(final HtmlOption selectedOption, final boolean isSelected) { return (P) setSelectedAttribute(selectedOption, isSelected, true, true, false, true); }
/** * Selects the option with the specified value. * @param newValue the value of the option to select */ @Override public void jsxSet_value(final String newValue) { getHtmlSelect().setSelectedAttribute(newValue, true); }
/** * Selects the option with the specified value. * @param newValue the value of the option to select */ @Override public void jsxSet_value(final String newValue) { getHtmlSelect().setSelectedAttribute(newValue, true); }
/** * Selects the option with the specified value. * @param newValue the value of the option to select */ @Override public void jsxSet_value(final String newValue) { getHtmlSelect().setSelectedAttribute(newValue, true); }
[........] final HtmlSelect selectBase = form.getSelectByName("event.datapool"); final HtmlOption optionBase = selectBase.getOptionByText("Freizeit / Tourismus"); final Page newPage = selectBase.setSelectedAttribute(optionBase, true); [........]
/** * Selects the option with the specified value. * @param newValue the value of the option to select */ @Override public void setValue(final Object newValue) { final String val = Context.toString(newValue); getHtmlSelect().setSelectedAttribute(val, true, false); }
/** * Selects the option with the specified value. * @param newValue the value of the option to select */ @Override public void setValue(final Object newValue) { final String val = Context.toString(newValue); getHtmlSelect().setSelectedAttribute(val, true, false); }
HtmlSelect select = page.getHtmlElementById("myId"); for (HtmlOption o : select.getOptions()) { if (o.getValueAttribute().contains("myValue")) { select.setSelectedAttribute(o, true); } }
/** * {@inheritDoc} */ @Override public void insertBefore(final DomNode newNode) { super.insertBefore(newNode); if (newNode instanceof HtmlOption) { final HtmlOption option = (HtmlOption) newNode; if (option.isSelected()) { getEnclosingSelect().setSelectedAttribute(option, true); } } }
/** * {@inheritDoc} */ @Override public void insertBefore(final DomNode newNode) throws IllegalStateException { super.insertBefore(newNode); if (newNode instanceof HtmlOption) { final HtmlOption option = (HtmlOption) newNode; if (option.isSelected()) { getEnclosingSelect().setSelectedAttribute(option, true); } } }
final WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://www.census.gov/manufacturing/m3/"); HtmlSelect select = (HtmlSelect) page.getElementByName("advanced_xls"); InputStream is = select.setSelectedAttribute("/manufacturing/m3/adv/table2a.xls",true).getWebResponse().getContentAsStream();
/** * {@inheritDoc} */ @Override public void insertBefore(final DomNode newNode) { super.insertBefore(newNode); if (newNode instanceof HtmlOption) { final HtmlOption option = (HtmlOption) newNode; if (option.isSelected()) { getEnclosingSelect().setSelectedAttribute(option, true); } } }
/** * {@inheritDoc} */ @Override public void insertBefore(final DomNode newNode) throws IllegalStateException { super.insertBefore(newNode); if (newNode instanceof HtmlOption) { final HtmlOption option = (HtmlOption) newNode; if (option.isSelected()) { getEnclosingSelect().setSelectedAttribute(option, true); } } }