List of usage examples for org.openqa.selenium WebElement isSelected
boolean isSelected();
From source file:org.paxml.selenium.webdriver.IsSelectedTag.java
License:Open Source License
/** * {@inheritDoc}// ww w. ja v a2 s . c o m */ @Override protected Object onCommand(Context context) { return handleElements(new IElementHandler() { public Object handle(WebElement ele) { return ele.isSelected(); } }); }
From source file:org.powertools.web.WebDriverBrowser.java
License:Open Source License
private boolean setCheckboxValue(By locator, final boolean value) { return executeCommandWhenElementAvailable(locator, mShortDefaultTimeoutInSeconds, new WebCommand() { @Override/* w w w . j a v a 2s.c o m*/ public boolean execute(WebElement element) { boolean current = element.isSelected(); if (current != value) { element.click(); } return true; } }); }
From source file:org.qe4j.web.OpenWebDriver.java
License:Open Source License
/** * Finds and gets input value attribute of specified element. * * @param by/*from w ww. j a va2 s.c o m*/ * web driver identifier * * @return String value else null if no element is found to be selected */ public String getInputValue(By by) { WebElement webElement = null; List<WebElement> elements = findElements(by); // for single elements, check if it's a select menu if (elements.size() == 1) { if (elements.get(0).getTagName().equals("select")) { webElement = new Select(elements.get(0)).getFirstSelectedOption(); } else { webElement = elements.get(0); } } else { // search for the selected value to return if (elements.get(0).getAttribute("type").equals("radio") || elements.get(0).getAttribute("type").equals("checkbox")) { for (WebElement element : elements) { if (element.isSelected()) { webElement = element; break; } } } else { log.warn("multiple elements found, but unable to process more than the first"); webElement = elements.get(0); } } // return null if nothing is selected if (webElement == null) { log.warn("no input element was found to be selected based on locator {}", by.toString()); return null; } // normalize empty string values to nulls as they would be defined in // most expected output objects String value = webElement.getAttribute("value"); if (value.equals("")) { return null; } return value; }
From source file:org.richfaces.showcase.extendedDataTable.page.EDTSelectionPage.java
License:Open Source License
public void setSelectionMode(SelectionMode mode) { WebElement radio = null; switch (mode) { case SINGLE://from ww w . j a v a 2 s . c o m radio = radios.get(0); break; case MULTIPLE: radio = radios.get(1); break; case MULTIPLE_KEYBOARD_FREE: radio = radios.get(2); } if (!radio.isSelected()) { Graphene.guardAjax(radio).click(); } }
From source file:org.richfaces.tests.metamer.ftest.richColumn.AbstractColumnSortingTest.java
License:Open Source License
private void selectOrder(WebElement button) { if (!button.isSelected()) { Graphene.guardAjax(button).click(); } }
From source file:org.richfaces.tests.metamer.ftest.webdriver.Attributes.java
License:Open Source License
private void applyRadio(Tag tag, String valueToBeSet) { Validate.notEmpty(tag.radioElements, "No options from which can be selected."); for (WebElement element : tag.radioElements) { String attributeValue = element.getAttribute("value"); if (valueToBeSet.equals(NULLSTRING)) { if (new StringEqualsWrapper(attributeValue).isSimilarToSomeOfThis(NULLSTRINGOPTIONS)) { if (!element.isSelected()) { waitGuard(element).click(); }// w w w . j a v a2 s .c o m return; } } else if (valueToBeSet.equals(attributeValue)) { if (!element.isSelected()) { waitGuard(element).click(); } return; } else if (attributeValue.contains(valueToBeSet)) { //for image selection radios, which value contains a source url of the image if (!element.isSelected()) { waitGuard(element).click(); } return; } } throw new IllegalArgumentException("No property with value " + valueToBeSet + " was found"); }
From source file:org.richfaces.tests.metamer.ftest.webdriver.Attributes.java
License:Open Source License
private void applySelect(Tag tag, String value) { Validate.notEmpty(tag.selection.getOptions(), "No options from which can be selected."); if (value.equals(NULLSTRING)) { for (WebElement element : tag.selection.getOptions()) { String val = element.getAttribute("value"); if (new StringEqualsWrapper(val).isSimilarToSomeOfThis(NULLSTRINGOPTIONS)) { if (!element.isSelected()) { waitGuard(element).click(); }/*w w w. j a v a 2s . c o m*/ return; } } } else { tag.selection.selectByValue(value); return; } throw new IllegalArgumentException("No property with value " + value + " was found"); }
From source file:org.richfaces.tests.metamer.ftest.webdriver.Attributes.java
License:Open Source License
private String getValueFromRadio(Tag tag) { Validate.notEmpty(tag.radioElements, "No inputs for this attribute found"); WebElement nullSelectionOption = null; for (WebElement webElement : tag.radioElements) { String value = webElement.getAttribute("value"); if (new StringEqualsWrapper(value).isSimilarToSomeOfThis(NULLSTRINGOPTIONS)) { nullSelectionOption = webElement; }// w ww. j a v a 2 s. co m if (webElement.isSelected()) { return webElement.getAttribute("value"); } } if (nullSelectionOption != null) { //workaround for String options with value="" , used in attributes like //action, actionListener, model... //they do not preserve its selected state return NULLSTRING; } throw new IllegalArgumentException("No selected choice for this attribute found."); }
From source file:org.richfaces.tests.metamer.ftest.webdriver.Attributes.java
License:Open Source License
private String getValueFromSelect(Tag tag) { Validate.notEmpty(tag.selection.getOptions(), "No inputs for this attribute found"); WebElement nullSelectionOption = null; for (WebElement webElement : tag.selection.getAllSelectedOptions()) { String value = webElement.getAttribute("value"); if (new StringEqualsWrapper(value).isSimilarToSomeOfThis(NULLSTRINGOPTIONS)) { nullSelectionOption = webElement; }//from w w w. j av a 2s. c o m if (webElement.isSelected()) { return webElement.getAttribute("value"); } } if (nullSelectionOption != null) { //workaround for String options with value="" , used in attributes like //action, actionListener, model... //they do not preserve its selected state return NULLSTRING; } throw new IllegalArgumentException("No selected choice for this attribute found."); }
From source file:org.richfaces.tests.showcase.extendedDataTable.page.EDTSelectionPage.java
License:Open Source License
public void setSelectionMode(SelectionMode mode) { WebElement radio = null; switch (mode) { case SINGLE:/*from w ww . j a va 2s . c om*/ radio = radios.get(0); break; case MULTIPLE: radio = radios.get(1); break; case MULTIPLE_KEYBOARD_FREE: radio = radios.get(2); } if (!radio.isSelected()) { Graphene.guardXhr(radio).click(); } }