/** * {@inheritDoc} */ @Override protected void preventDefault() { setChecked(!isChecked()); }
/** * {@inheritDoc} */ @Override public Page setChecked(final boolean isChecked) { if (isChecked) { setAttribute("checked", "checked"); } else { removeAttribute("checked"); } return executeOnChangeHandlerIfAppropriate(this); }
/** * Creates an instance. * If no value is specified, it is set to "on" as browsers do (e.g. 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 */ HtmlCheckBoxInput(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(namespaceURI, qualifiedName, page, attributes); //From the checkbox creator defaultCheckedState_ = hasAttribute("checked"); // 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"); } }
/** * {@inheritDoc} */ @Override protected void doClickFireChangeEvent() { if (hasFeature(EVENT_ONCHANGE_AFTER_ONCLICK)) { executeOnChangeHandlerIfAppropriate(this); } }
@Override Object getInternalValue() { return isChecked(); }
/** * {@inheritDoc} * * @see SubmittableElement#reset() */ @Override public void reset() { setChecked(defaultCheckedState_); }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultChecked(boolean) */ @Override public void setDefaultChecked(final boolean defaultChecked) { defaultCheckedState_ = defaultChecked; if (getPage().getWebClient().getBrowserVersion().isFirefox()) { setChecked(defaultChecked); } }
result = new HtmlCheckBoxInput(namespaceURI, qualifiedName, page, attributeMap);
/** * 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 */ HtmlCheckBoxInput(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_; }
/** * {@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); }
HtmlCheckBoxInput checkbox = (HtmlCheckBoxInput) page.getElementById("cb4"); checkbox.setAttribute("checked", "checked"); checkbox.fireEvent(Event.TYPE_CHANGE); page.refresh(); System.out.println(page.asXml());
/** * {@inheritDoc} */ @Override public Page setChecked(final boolean isChecked) { checkedState_ = isChecked; return executeOnChangeHandlerIfAppropriate(this); }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { // disable caching webClient.getCache().setMaxSize(0); // Get the first page final HtmlPage page1 = webClient.getPage(url); final HtmlForm form = page1.getFormByName(formName); final HtmlTextInput taxCodeTextField = form.getInputByName(taxCodeTextFieldName); HtmlCheckBoxInput checkboxInput = form.getInputByName(checkboxInputName); taxCodeTextField.type(taxCode); checkboxInput.click(); //wait a little Thread.sleep(2000); //get the main page HtmlPage page2 = (HtmlPage) webClient.getTopLevelWindows().get(0).getEnclosedPage(); HtmlSubmitInput confirmButton = page2.getFormByName(formName).getInputByName(confirmButtonName); final HtmlPage page3 = confirmButton.click(); System.out.println(page3.asText()); }
/** * A checkbox 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#reset() */ @Override public void reset() { setChecked(defaultCheckedState_); }
/** * {@inheritDoc} * @see SubmittableElement#setDefaultChecked(boolean) */ @Override public void setDefaultChecked(final boolean defaultChecked) { defaultCheckedState_ = defaultChecked; if (getPage().getWebClient().getBrowserVersion().isFirefox()) { setChecked(defaultChecked); } }
result = new HtmlCheckBoxInput(namespaceURI, qualifiedName, page, attributeMap);
/** * {@inheritDoc} */ @Override protected void doClickFireChangeEvent() { if (hasFeature(EVENT_ONCHANGE_AFTER_ONCLICK)) { executeOnChangeHandlerIfAppropriate(this); } }