Java Code Examples for org.openqa.selenium.WebElement#isSelected()
The following examples show how to use
org.openqa.selenium.WebElement#isSelected() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiddenHtmlMultiSelectList.java From ats-framework with Apache License 2.0 | 6 votes |
/** * unselect a value * * @param value the value to unselect */ @Override @PublicAtsApi public void unsetValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement el : optionElements) { if (el.getText().equals(value)) { if (el.isSelected()) { ((HtmlUnitWebElement) el).click(); UiEngineUtilities.sleep(); } return; } } throw new SeleniumOperationException("Option with label '" + value + "' not found. (" + this.toString() + ")"); }
Example 2
Source File: JavaDriverTest.java From marathonv5 with Apache License 2.0 | 6 votes |
public void isSelectedOnNonSelectableComponents() throws Throwable { driver = new JavaDriver(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame.setLocationRelativeTo(null); frame.setVisible(true); } }); WebElement element1 = driver.findElement(By.name("text-field")); try { element1.isSelected(); throw new MissingException(UnsupportedCommandException.class); } catch (UnsupportedCommandException e) { } }
Example 3
Source File: CheckBox.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
@Action(object = ObjectType.BROWSER, desc = "Check all the check boxes in the context") public void checkAllCheckBoxes() { try { List<WebElement> checkboxes = Driver.findElements(By.cssSelector("input[type=checkbox]")); if (checkboxes.isEmpty()) { Report.updateTestLog(Action, "No Checkbox present in the page", Status.WARNING); } else { for (WebElement checkbox : checkboxes) { if (checkbox.isDisplayed() && !checkbox.isSelected()) { checkbox.click(); } } Report.updateTestLog(Action, "All checkboxes are checked", Status.PASS); } } catch (Exception ex) { Report.updateTestLog(Action, "Error while checking checkboxes - " + ex, Status.FAIL); Logger.getLogger(CheckBox.class.getName()).log(Level.SEVERE, null, ex); } }
Example 4
Source File: SelectList.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
public void deselectByIndex(final int index) { TestLogging.logWebStep("deselect index\"" + index + "\" on " + toHTML(), false); findElement(); WebElement option = options.get(index); if (option.isSelected()) { option.click(); } }
Example 5
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 5 votes |
/** * 'uncheck' the check box, if it is not already 'unchecked'. * No action taken if it is already 'unchecked'. */ protected void markCheckBoxAsUnchecked(WebElement checkBox) { waitForElementVisibility(checkBox); if (checkBox.isSelected()) { click(checkBox); } }
Example 6
Source File: QueueSubscriptionsPage.java From product-ei with Apache License 2.0 | 5 votes |
/** * Search queue subscriptions according to the search criteria. * * @param queueNamePattern string pattern of the queue name (* for all) * @param identifierPattern string pattern of the identifier (* for all) * @param ownNodeIdIndex index of the node Id in the dropdown the subscriptions belong to * @return number of subscriptions listed under search result */ public int searchQueueSubscriptions(String queueNamePattern, String identifierPattern, int ownNodeIdIndex, boolean isNameExactMatch, boolean isIdentifierExactMatch) { WebElement queueNamePatternField = driver.findElement(By.name(UIElementMapper.getInstance() .getElement("mb.search.queue.name.pattern.tag.name"))); queueNamePatternField.clear(); queueNamePatternField.sendKeys(queueNamePattern); WebElement queueNameExactMatchField = driver.findElement( By.name(UIElementMapper.getInstance().getElement("mb.search.queue.name.exactmatch.tag.name"))); // Set the name exact match check box state based on the test input if (isNameExactMatch != queueNameExactMatchField.isSelected()) { queueNameExactMatchField.click(); } WebElement queueIdentifierExactMatchField = driver.findElement( By.name(UIElementMapper.getInstance().getElement("mb.search.queue.identifier.exactmatch.tag.name"))); // Set the identifier exact match check box state based on the test input if (isIdentifierExactMatch != queueIdentifierExactMatchField.isSelected()) { queueIdentifierExactMatchField.click(); } WebElement queueIdentifierPatternField = driver.findElement(By.name(UIElementMapper.getInstance() .getElement("mb.search.queue.identifier.pattern.tag.name"))); queueIdentifierPatternField.clear(); queueIdentifierPatternField.sendKeys(identifierPattern); Select ownNodeIdDropdown = new Select(driver.findElement(By.id(UIElementMapper.getInstance() .getElement("mb.search.queue.own.node.id.element.id")))); ownNodeIdDropdown.selectByIndex(ownNodeIdIndex); driver.findElement(By.xpath(UIElementMapper.getInstance() .getElement("mb.search.queue.search.button.xpath"))).click(); return getSubscriptionCount(); }
Example 7
Source File: HiddenHtmlMultiSelectList.java From ats-framework with Apache License 2.0 | 5 votes |
/** * select a value * * @param value the value to select */ @Override @PublicAtsApi public void setValue( String value ) { new HiddenHtmlElementState(this).waitToBecomeExisting(); HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this); if (selectElement.getAttribute("multiple") == null) { throw new SeleniumOperationException("Not a multi-select. You may only add a selection to a select that supports multiple selections. (" + this.toString() + ")"); } List<WebElement> optionElements = selectElement.findElements(By.tagName("option")); for (WebElement el : optionElements) { if (el.getText().equals(value)) { if (!el.isSelected()) { ((HtmlUnitWebElement) el).click(); UiEngineUtilities.sleep(); } return; } } throw new SeleniumOperationException("Option with label '" + value + "' not found. (" + this.toString() + ")"); }
Example 8
Source File: Check.java From selenium with Apache License 2.0 | 5 votes |
@Override protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) { alertOverride.replaceAlertMethod(driver); WebElement element = finder.findElement(driver, locator); if (!element.isSelected()) { element.click(); } return null; }
Example 9
Source File: SelectList.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
public String getSelectedText() { findElement(); for (WebElement option : options) { if (option.isSelected()) { return option.getAttribute("text"); } } return null; }
Example 10
Source File: QueueAddPage.java From product-ei with Apache License 2.0 | 5 votes |
/** * Adds a queue without privileges to any role or not explicitly specified * @param qName queue name * @param withoutPrivileges without privileges set to roles to consume or publish * @return true if successful and false otherwise * @throws IOException */ public boolean addQueue(final String qName, boolean withoutPrivileges) throws IOException{ boolean isSuccessful = false; WebElement qNameField = driver.findElement(By.id(UIElementMapper.getInstance() .getElement("mb.add.queue.page.qname.field.id"))); qNameField.sendKeys(qName); if(withoutPrivileges) { // get permission table WebElement table = driver.findElement(By.xpath(UIElementMapper.getInstance() .getElement("mb.add.queue.page.permission.table"))); // get role name related publish consume checkboxes list for all the roles List<WebElement> checkBoxList = table.findElements(By.tagName("input")); // make all the permissions unchecked for (WebElement element: checkBoxList) { if(element.isSelected()) { element.click(); // uncheck checkbox } } } driver.getWindowHandle(); driver.findElement(By.xpath(UIElementMapper.getInstance() .getElement("mb.add.queue.page.add.button.xpath"))).click(); String dialog = driver.getWindowHandle(); driver.switchTo().window(dialog); if(driver.findElement(By.id(UIElementMapper.getInstance() .getElement("mb.popup.dialog.id"))).getText().contains("Queue added successfully")) { isSuccessful =true; } driver.findElement(By.xpath(UIElementMapper.getInstance().getElement("mb.add.queue.page" + ".onqueueadd.okbutton.xpath"))).click(); return isSuccessful; }
Example 11
Source File: AbstractSeleniumTest.java From archiva with Apache License 2.0 | 5 votes |
public void checkField( String locator ) { WebElement element = findElement(locator ); if (!element.isSelected()) { element.click(); } }
Example 12
Source File: FormService.java From senbot with MIT License | 5 votes |
public void uncheckCheckboxOnView(String view, String checkboxRef) throws IllegalArgumentException, IllegalAccessException { WebElement elementFromReferencedView = seleniumElementService.getElementFromReferencedView(view, checkboxRef); if(elementFromReferencedView.isSelected()) { elementFromReferencedView.click(); } }
Example 13
Source File: CheckBox.java From JTAF-ExtWebDriver with Apache License 2.0 | 5 votes |
/** * * @param e * WebElement to check * @return boolean if attribute is selected * @throws Exception */ private static boolean isSelected(WebElement e) throws Exception { try { return e.isSelected(); } catch (Exception exception) { try { String attribute = e.getAttribute("value"); return attribute != null && attribute.equalsIgnoreCase("on"); } catch (Exception exception2) { throw exception; } } }
Example 14
Source File: FlowsTable.java From keycloak with Apache License 2.0 | 5 votes |
public Map<String, String> getFlowsAliasesWithRequirements(){ Map<String, String> flows = new LinkedHashMap<>(); List<WebElement> aliases = tbody.findElements(By.xpath("//span[@class='ng-binding']")); for(WebElement alias : aliases) { List<WebElement> requirementsOptions = alias.findElements(By.xpath(".//../parent::*//input[@type='radio']")); for (WebElement requirement : requirementsOptions) { if (requirement.isSelected()) { flows.put(getTextFromElement(alias), requirement.getAttribute("value")); } } } return flows; }
Example 15
Source File: Step.java From NoraUi with GNU Affero General Public License v3.0 | 4 votes |
/** * Checks a checkbox type element (value corresponding to key "valueKey"). * * @param element * Target page element. * @param valueKeyOrKey * is valueKey (valueKey or key in context (after a save)) to match in values map * @param values * Values map. * @param args * list of arguments to format the found selector with. * @throws TechnicalException * is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi. * Failure with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT} message (with screenshot) * @throws FailureException * if the scenario encounters a functional error. */ protected void selectCheckbox(PageElement element, String valueKeyOrKey, Map<String, Boolean> values, Object... args) throws TechnicalException, FailureException { final String valueKey = Context.getValue(valueKeyOrKey) != null ? Context.getValue(valueKeyOrKey) : valueKeyOrKey; try { final WebElement webElement = Wait.until(ExpectedConditions.elementToBeClickable(Utilities.getLocator(element, args))); Boolean checkboxValue = values.get(valueKey); if (checkboxValue == null) { checkboxValue = values.get("Default"); } if (webElement.isSelected() != checkboxValue.booleanValue()) { webElement.click(); } } catch (final Exception e) { new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT), element, element.getPage().getApplication()), true, element.getPage().getCallBack()); } }
Example 16
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isRankDuplicatesAllowedChecked(int qnIndex) { WebElement checkBox = browser.driver.findElement(By.id("rankAreDuplicatesAllowed-" + qnIndex)); return checkBox.isSelected(); }
Example 17
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 4 votes |
@Override protected boolean _isSelected() { WebElement webElement = getElement(); return webElement.isSelected(); }
Example 18
Source File: SelectionChangedEvent.java From webtester2-core with Apache License 2.0 | 4 votes |
@Override public PageFragmentEventBuilder<SelectionChangedEvent> setAfterData(WebElement webElement) { this.after = webElement.isSelected(); return this; }
Example 19
Source File: AsyncDemoIT.java From portals-pluto with Apache License 2.0 | 4 votes |
private boolean isChecked(String xpath) { WebElement checkbox = driver.findElement(By.xpath(xpath)); return checkbox.isSelected(); }
Example 20
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isCheckboxChecked(String checkboxClass, String checkboxValue, int questionNumber) { By checkboxSelector = By.cssSelector("#questionTable-" + questionNumber + " input[value='" + checkboxValue + "']." + checkboxClass); WebElement checkbox = browser.driver.findElement(checkboxSelector); return checkbox.isSelected(); }