List of usage examples for org.openqa.selenium WebElement isSelected
boolean isSelected();
From source file:com.hotwire.test.steps.helpcenter.SalesforceHelpCenterModel.java
License:Open Source License
public void switchSFAdminCategory(String category) { //Too many sub pages, that's why without page object's. Also this method will be used only for one scenario. new WebDriverWait(getWebdriverInstance(), 2) .until(ExpectedConditions.visibilityOfElementLocated(By.name("go"))).click(); //Paste category name to xpath locator String editCategory = String.format(EDIT_CATEGORY_TEMP, category); new WebDriverWait(getWebdriverInstance(), 4) .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(editCategory))).click(); new WebDriverWait(getWebdriverInstance(), 2) .until(ExpectedConditions.visibilityOfElementLocated(By.name("save"))); List<WebElement> checks = getWebdriverInstance().findElements(By.cssSelector("table.detailList input")); for (WebElement check : checks) { if (helpCenterInfo.getMode().equals(HelpCenterInfo.CONTACTS_MODE.ON)) { if (!check.isSelected()) { check.click();//w ww . j a va 2 s .c o m } } else { if (check.isSelected()) { check.click(); } } } getWebdriverInstance().findElement(By.name("save")).click(); }
From source file:com.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java
License:Open Source License
/** * Determine whether or not this element is selected or not. This operation * only applies to input elements such as checkboxes, options in a select * and radio buttons./*from w w w .java2 s . c o m*/ * * @return True if the element is currently selected or checked, false * otherwise. */ public boolean isSelected(int numRetries) { boolean elemSelected = false; WebElement webElem = null; for (int i = 0; i <= numRetries; i++) { try { webElem = browser.getSeleniumWebDriver().findElement(domObject.getLocatorAsBy()); if (webElem != null && webElem.isSelected()) { elemSelected = true; break; } } catch (Throwable th) { if (i == numRetries) { break; } } browser.waitForSeconds(2); } return elemSelected; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.CheckBoxValidatorSD.java
License:Open Source License
@Override public boolean isCheckBoxChecked(int numRetries) { WebElement webElem = findElement(numRetries); return webElem.isSelected(); }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void validateSelectedItem(String expectedSelectedValue, TextValidationMechanism validationMechanism, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;/* w w w. j a va2s.c om*/ boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected() && matchTextValue(optionTextValue.trim(), expectedSelectedValue, validationMechanism)) { found = true; break; } } if (!found) { Assert.fail("Failed to find selected item '" + expectedSelectedValue + "' in ComboBox '" + uiObject.getDisplayName() + "'."); } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public String getSelectedItem(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;/*from w w w. ja v a2s. co m*/ for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { return optionTextValue; } } return null; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public List<String> getSelectedItems(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); List<String> selectedItems = new LinkedList<String>(); String optionTextValue;/* w w w . j a va 2 s . c o m*/ for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { selectedItems.add(optionTextValue); } } return selectedItems; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java
License:Open Source License
@Override public void validateSelectedItem(String expectedSelectedValue, TextValidationMechanism validationMechanism, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;//w w w. j a v a2 s. co m boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected() && matchTextValue(optionTextValue.trim(), expectedSelectedValue, validationMechanism)) { found = true; break; } } if (!found) { Assert.fail("Failed to find selected item '" + expectedSelectedValue + "' in ListBox '" + uiObject.getDisplayName() + "'."); } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java
License:Open Source License
@Override public String getSelectedItem(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;// w w w . j a va2 s . c o m for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { return optionTextValue; } } return null; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java
License:Open Source License
@Override public List<String> getSelectedItems(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ListBox '" + uiObject.getDisplayName() + "'. Found 0 items."); List<String> selectedItems = new LinkedList<String>(); String optionTextValue;/* ww w.j a v a 2 s .co m*/ for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { selectedItems.add(optionTextValue); } } return selectedItems; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ListBoxValidatorSD.java
License:Open Source License
@Override public void selectItem(String itemName, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ListBox '" + uiObject.getDisplayName() + "'."); String optionTextValue;/*from w w w .j a v a 2 s.c om*/ boolean found = false; //performAction(new KeyboardEvent(KeyboardEventName.kbKeyUp, Keys.CONTROL, null), 0); for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && itemName.equals(optionTextValue.trim())) { if (!option.isSelected()) { option.click(); } found = true; //break; } else if (option.isSelected()) { option.click(); } } if (!found) { Assert.fail("Failed to find item '" + itemName + "' in ListBox '" + uiObject.getDisplayName() + "'."); } }