/** * {@inheritDoc} */ @Override protected DomNode getEventTargetElement() { if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) { final HtmlSelect select = getEnclosingSelect(); if (select != null) { return select; } } return super.getEventTargetElement(); }
/** * {@inheritDoc} */ @Override protected DomNode getEventTargetElement() { if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) { final HtmlSelect select = getEnclosingSelect(); if (select != null) { return select; } } return super.getEventTargetElement(); }
/** * {@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); } } }
/** * {@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); } } }
/** * {@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); } } }
/** * {@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); } } }
/** * Returns the {@code index} property. * @return the {@code index} property */ @JsxGetter public int getIndex() { final HtmlOption optionNode = (HtmlOption) getDomNodeOrNull(); if (optionNode != null) { final HtmlSelect enclosingSelect = optionNode.getEnclosingSelect(); if (enclosingSelect != null) { return enclosingSelect.indexOf(optionNode); } } return 0; }
/** * Returns the {@code index} property. * @return the {@code index} property */ @JsxGetter public int getIndex() { final HtmlOption optionNode = (HtmlOption) getDomNodeOrNull(); if (optionNode != null) { final HtmlSelect enclosingSelect = optionNode.getEnclosingSelect(); if (enclosingSelect != null) { return enclosingSelect.indexOf(optionNode); } } return 0; }
/** * Sets the selected state of this option. This will possibly also change the * selected properties of sibling option elements. * * @param selected true if this option should be selected * @param invokeOnFocus whether to set focus or not. * @param isClick is mouse clicked * @param shiftKey {@code true} if SHIFT is pressed * @param ctrlKey {@code true} if CTRL is pressed */ private void setSelected(final boolean selected, final boolean invokeOnFocus, final boolean isClick, final boolean shiftKey, final boolean ctrlKey) { if (selected == isSelected()) { return; } final HtmlSelect select = getEnclosingSelect(); if (select != null) { select.setSelectedAttribute(this, selected, invokeOnFocus, shiftKey, ctrlKey, isClick); return; } // for instance from JS for an option created by document.createElement('option') // and not yet added to a select setSelectedInternal(selected); }
/** * Selects the option if it's not already selected. * {@inheritDoc} */ @Override protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException { boolean changed = false; if (!isSelected()) { setSelected(true, true, true, shiftKey, ctrlKey); changed = true; } else if (getEnclosingSelect().isMultipleSelectEnabled()) { if (ctrlKey) { setSelected(false, true, true, shiftKey, ctrlKey); changed = true; } else { getEnclosingSelect().setOnlySelected(this, true); } } super.doClickStateUpdate(shiftKey, ctrlKey); return changed; }
/** * Selects the option if it's not already selected. * {@inheritDoc} */ @Override public Page mouseUp(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { Page page = null; if (hasFeature(EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); } if (hasFeature(EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION)) { return page; } return super.mouseUp(shiftKey, ctrlKey, altKey, button); }
/** * Selects the option if it's not already selected. * {@inheritDoc} */ @Override public Page mouseDown(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { Page page = null; if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT)) { page = getEnclosingSelect().mouseDown(shiftKey, ctrlKey, altKey, button); } if (hasFeature(EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION)) { return page; } return super.mouseDown(shiftKey, ctrlKey, altKey, button); }
/** * Selects the option if it's not already selected. * {@inheritDoc} */ @Override public Page mouseUp(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { Page page = null; if (hasFeature(EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); } if (hasFeature(EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION)) { return page; } return super.mouseUp(shiftKey, ctrlKey, altKey, button); }
/** * Selects the option if it's not already selected. * {@inheritDoc} */ @Override public Page mouseDown(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { Page page = null; if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT)) { page = getEnclosingSelect().mouseDown(shiftKey, ctrlKey, altKey, button); } if (hasFeature(EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION)) { return page; } return super.mouseDown(shiftKey, ctrlKey, altKey, button); }
/** * Sets the value of the {@code selected} property. * @param selected the new selected property */ @JsxSetter public void setSelected(final boolean selected) { final HtmlOption optionNode = (HtmlOption) getDomNodeOrNull(); final HtmlSelect enclosingSelect = optionNode.getEnclosingSelect(); if (!selected && optionNode.isSelected() && enclosingSelect != null && !enclosingSelect.isMultipleSelectEnabled()) { enclosingSelect.getOption(0).setSelectedFromJavaScript(true); } else { optionNode.setSelectedFromJavaScript(selected); } }
public boolean toggle() { assertElementNotStale(); try { if (element instanceof HtmlCheckBoxInput) { ((HtmlCheckBoxInput) element).click(); return isSelected(); } if (element instanceof HtmlOption) { HtmlOption option = (HtmlOption) element; HtmlSelect select = option.getEnclosingSelect(); if (select.isMultipleSelectEnabled()) { option.setSelected(!option.isSelected()); return isSelected(); } } throw new UnsupportedOperationException("You may only toggle checkboxes or options in a select which allows multiple selections: " + getTagName()); } catch (IOException e) { throw new WebDriverException("Unexpected exception: " + e); } }
/** * Sets the value of the {@code selected} property. * @param selected the new selected property */ @JsxSetter public void setSelected(final boolean selected) { final HtmlOption optionNode = (HtmlOption) getDomNodeOrNull(); final HtmlSelect enclosingSelect = optionNode.getEnclosingSelect(); if (!selected && optionNode.isSelected() && enclosingSelect != null && !enclosingSelect.isMultipleSelectEnabled()) { enclosingSelect.getOption(0).setSelectedFromJavaScript(true); } else { optionNode.setSelectedFromJavaScript(selected); } }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <P extends Page> P click(final Event event, final boolean ignoreVisibility) throws IOException { if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) { final SgmlPage page = getPage(); if (isDisabled()) { return (P) page; } if (isStateUpdateFirst()) { doClickStateUpdate(event.isShiftKey(), event.isCtrlKey()); } return getEnclosingSelect().click(event, ignoreVisibility); } return super.click(event, ignoreVisibility); }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <P extends Page> P click(final Event event, final boolean ignoreVisibility) throws IOException { if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) { final SgmlPage page = getPage(); if (isDisabled()) { return (P) page; } if (isStateUpdateFirst()) { doClickStateUpdate(event.isShiftKey(), event.isCtrlKey()); } return getEnclosingSelect().click(event, ignoreVisibility); } return super.click(event, ignoreVisibility); }