Refine search
@Override public String getSelectedRadio(String radioGroup) { List<HtmlRadioButtonInput> radios = getForm().getRadioButtonsByName(radioGroup); for (HtmlRadioButtonInput radio : radios) { if (radio.isChecked()) { return radio.getValueAttribute(); } } throw new RuntimeException("Unexpected state: no radio button was selected in radio group [" + radioGroup + "]. Is it possible in a real browser?"); }
/** * {@inheritDoc} */ @Override protected void onAddedToPage() { super.onAddedToPage(); setChecked(isChecked()); }
/** * Selects the specified radio button in the form. Only a radio button that is actually contained * in the form can be selected. * * @param radioButtonInput the radio button to select */ void setCheckedRadioButton(final HtmlRadioButtonInput radioButtonInput) { if (!isAncestorOf(radioButtonInput) && !lostChildren_.contains(radioButtonInput)) { throw new IllegalArgumentException("HtmlRadioButtonInput is not child of this HtmlForm"); } final List<HtmlRadioButtonInput> radios = getRadioButtonsByName(radioButtonInput.getNameAttribute()); for (final HtmlRadioButtonInput input : radios) { if (input == radioButtonInput) { input.setAttribute("checked", "checked"); } else { input.removeAttribute("checked"); } } }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultChecked(boolean) */ @Override public void setDefaultChecked(final boolean defaultChecked) { defaultCheckedState_ = defaultChecked; setChecked(isDefaultChecked()); }
/** * Creates an instance. * If no value is specified, it is set to "on" as browsers do (eg IE6 and Mozilla 1.7) * even if spec says that it is not allowed * (<a href="http://www.w3.org/TR/REC-html40/interact/forms.html#adef-value-INPUT">W3C</a>). * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes the initial attributes */ HtmlRadioButtonInput(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(namespaceURI, qualifiedName, page, attributes); // default value for both IE6 and Mozilla 1.7 even if spec says it is unspecified if (getAttribute("value") == ATTRIBUTE_NOT_DEFINED) { setAttribute("value", "on"); } defaultCheckedState_ = hasAttribute("checked"); }
/** * Creates an instance. * If no value is specified, it is set to "on" as browsers do * even if spec says that it is not allowed * (<a href="http://www.w3.org/TR/REC-html40/interact/forms.html#adef-value-INPUT">W3C</a>). * * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes the initial attributes */ HtmlRadioButtonInput(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(qualifiedName, page, addValueIfNeeded(page, attributes)); // fix the default value in case we have set it if (getAttributeDirect("value") == DEFAULT_VALUE) { setDefaultValue(ATTRIBUTE_NOT_DEFINED, false); } defaultCheckedState_ = hasAttribute("checked"); checkedState_ = defaultCheckedState_; }
/** * Add a GerritServer with default configs from the UI. * * @param serverName the name * @throws Exception if error getting URL or getting page from URL. */ private void addNewServerWithDefaultConfigs(String serverName) throws Exception { URL url = new URL(j.getURL(), newServerURL); HtmlPage page = j.createWebClient().getPage(url); HtmlForm form = page.getFormByName(newServerFormName); form.getInputByName(inputFormName).setValueAttribute(serverName); List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName); HtmlRadioButtonInput radioButtonDefaultConfig = null; for (HtmlRadioButtonInput button : radioButtons) { if (radioButtonDefaultConfigValue.equals(button.getValueAttribute())) { radioButtonDefaultConfig = button; radioButtonDefaultConfig.setChecked(true); } } assertTrue("Failed to choose 'GerritServer with Default Configurations'", radioButtonDefaultConfig.isChecked()); j.submit(form); }
/** * Override of default clickAction that makes this radio button the selected * one when it is clicked. * {@inheritDoc} * * @throws IOException if an IO error occurred */ @Override protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException { final HtmlForm form = getEnclosingForm(); final boolean changed = !isChecked(); final Page page = getPage(); if (form != null) { form.setCheckedRadioButton(this); } else if (page != null && page.isHtmlPage()) { setCheckedForPage((HtmlPage) page); } super.doClickStateUpdate(shiftKey, ctrlKey); return changed; }
final HtmlForm form = getEnclosingForm(); final boolean changed = isChecked() != isChecked; form.setCheckedRadioButton(this); ((HtmlPage) getPage()).setCheckedRadioButton(this); removeAttribute("checked"); Page page = getPage(); final ScriptResult scriptResult = fireEvent(Event.TYPE_CHANGE); if (scriptResult != null) { page = scriptResult.getNewPage();
/** * Returns the first checked radio button with the specified name. If none of * the radio buttons by that name are checked, this method returns {@code null}. * * @param name the name of the radio button * @return the first checked radio button with the specified name */ public HtmlRadioButtonInput getCheckedRadioButton(final String name) { WebAssert.notNull("name", name); for (final HtmlRadioButtonInput input : getRadioButtonsByName(name)) { if (input.isChecked()) { return input; } } return null; }
/** * Makes sure that there's no JavaScript error in the new view page. */ @Test public void newViewPage() throws Exception { Folder f = createFolder(); HtmlPage p = r.createWebClient().getPage(f, "newView"); HtmlForm fm = p.getFormByName("createItem"); fm.getInputByName("name").setValueAttribute("abcView"); for (HtmlRadioButtonInput r : fm.getRadioButtonsByName("mode")) { if (r.getValueAttribute().equals(ListView.class.getName())) r.click(); } r.submit(fm); assertSame(ListView.class, f.getView("abcView").getClass()); }
/** * Selects the specified radio button in the form. Only a radio button that is actually contained * in the form can be selected. * * @param radioButtonInput the radio button to select */ void setCheckedRadioButton(final HtmlRadioButtonInput radioButtonInput) { if (!isAncestorOf(radioButtonInput) && !lostChildren_.contains(radioButtonInput)) { throw new IllegalArgumentException("HtmlRadioButtonInput is not child of this HtmlForm"); } final List<HtmlRadioButtonInput> radios = getRadioButtonsByName(radioButtonInput.getNameAttribute()); for (final HtmlRadioButtonInput input : radios) { input.setCheckedInternal(input == radioButtonInput); } }
HtmlTextInput name = form.getInputByName("name"); name.setValueAttribute(NAME); HtmlTextInput quest = form.getInputByName("quest"); quest.setValueAttribute(QUESTION); HtmlSelect color = form.getOneHtmlElementByAttribute("select", "name", "color"); List<HtmlOption> options = color.getOptions(); for(HtmlOption op:options){ HtmlRadioButtonInput swallow = form.getInputByValue(SWALLOW); swallow.click(); HtmlSubmitInput submit = form.getInputByValue("here");
/** * A radio button does not have a textual representation, * but we invent one for it because it is useful for testing. * @return "checked" or "unchecked" according to the radio state */ // we need to preserve this method as it is there since many versions with the above documentation. @Override public String asText() { if (isChecked()) { return "checked"; } return "unchecked"; }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultChecked(boolean) */ @Override public void setDefaultChecked(final boolean defaultChecked) { defaultCheckedState_ = defaultChecked; if (getPage().getWebClient().getBrowserVersion().isFirefox()) { setChecked(defaultChecked); } }
/** * Select the specified radio button in the page (outside any <form>). * * @param radioButtonInput the radio Button */ @SuppressWarnings("unchecked") void setCheckedRadioButton(final HtmlRadioButtonInput radioButtonInput) { // May be done in single XPath search? final List<HtmlRadioButtonInput> pageInputs = getByXPath("//input[lower-case(@type)='radio' " + "and @name='" + radioButtonInput.getNameAttribute() + "']"); final List<HtmlRadioButtonInput> formInputs = getByXPath("//form//input[lower-case(@type)='radio' " + "and @name='" + radioButtonInput.getNameAttribute() + "']"); pageInputs.removeAll(formInputs); for (final HtmlRadioButtonInput input : pageInputs) { if (input == radioButtonInput) { input.setAttribute("checked", "checked"); } else { input.removeAttribute("checked"); } } }
/** * {@inheritDoc} * @see SubmittableElement#reset() */ @Override public void reset() { setChecked(defaultCheckedState_); }
element = new HtmlForm(namespaceURI, qualifiedName, page, attributeMap); element = new HtmlRadioButtonInput(namespaceURI, qualifiedName, page, attributeMap);
/** * Clicks a radio option. Asserts that the radio option exists first. * * * @param radioGroup name of the radio group. * @param radioOption value of the option to check for. */ @Override public void clickRadioOption(String radioGroup, String radioOption) { HtmlRadioButtonInput rb = getRadioOption(radioGroup, radioOption); if (!rb.isChecked()) { try { rb.click(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("checkCheckbox failed", e); } } }
/** * {@inheritDoc} * Also sets the value to the new default value. * @see SubmittableElement#setDefaultValue(String) */ @Override public void setDefaultValue(final String defaultValue) { super.setDefaultValue(defaultValue); setValueAttribute(defaultValue); }