List of usage examples for org.openqa.selenium WebElement isSelected
boolean isSelected();
From source file:com.vilt.minium.impl.actions.SelectAllInteraction.java
License:Apache License
@Override protected void doPerform() { Select select = getSelectElement();// w ww .j a va 2s.co m if (!select.isMultiple()) { throw new UnsupportedOperationException("You may only deselect all options of a multi-select"); } for (WebElement option : select.getOptions()) { if (!option.isSelected()) { option.click(); } } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * check(locator) <br>/* w w w .ja va 2 s . c om*/ * Arguments:<br> * locator - an element locator<br> * Check a toggle-button (checkbox/radio)<br> * <br> * . * * @param objectName * : logical name of the object assigned by the user * @param isSelect * : specify whether to check or uncheck the button */ public final void check(final String objectName, final boolean isSelect) { int counter = getRetryCount(); String option = ""; // Getting the actual object identification from the object map String objectID = ObjectMap.getObjectSearchPath(objectName, locatorIdentifire); try { // Check whether the element present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; if (isSelect) { option = "Select"; // Calling the actual command if (!element.isSelected()) { element.click(); } /* selenium.check(objectID); */ reportresult(true, "CHECK (Select) :" + objectName + "", "PASSED", ""); } else { option = "DeSelect"; if (element.isSelected()) { element.click(); } /* selenium.uncheck(objectID); */ reportresult(true, "CHECK (DeSelect) :" + objectName + "", "PASSED", ""); } break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "CHECK : (" + option + ")" + objectName + "", "FAILED", "CHECK command cannot access :Element (" + objectName + ") [" + objectID + "]"); checkTrue(false, true, "CHECK command cannot access :Element (" + objectName + ") [" + objectID + "]"); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if any exception was raised, report a test failure e.printStackTrace(); reportresult(true, "CHECK (" + option + "):" + objectName + "", "FAILED", "CHECK (" + option + ") (" + objectName + ") [" + objectID + "] element not present"); checkTrue(false, true, "CHECK (" + option + ") (" + objectName + ") [" + objectID + "] element not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Validating the value of the given property of the object, further * continuation of the script execution will be decided <br> * besed on value of the <b> stopExecution </b> parameter provided by the * user <br>//from w w w .ja v a 2s . c o m * <br> * in the web page. * * @param element * the element * @param propertyname * : Name of the object property to be validated * @return the string * @throws Exception * the exception */ private String validateObjectProperty(final WebElement element, final String propertyname) throws Exception { String attributeValue = ""; if ("textContent".equals(propertyname)) { try { attributeValue = element.getText(); } catch (Exception ex) { throw new Exception("Attribute " + propertyname, ex); } } else if ("checked".equals(propertyname)) { try { if (element.isSelected()) { attributeValue = "true"; } else { attributeValue = "false"; } } catch (Exception ex) { throw new Exception("Attribute " + propertyname, ex); } } else { try { attributeValue = element.getAttribute(propertyname); if (attributeValue == null) { throw new Exception("Attribute " + propertyname); } } catch (Exception e1) { throw new Exception("Attribute " + propertyname, e1); } } return attributeValue; }
From source file:core.PluginManagerTest.java
License:Open Source License
@Test @WithPlugins("gerrit-trigger") public void uninstall_plugin() throws InterruptedException, ExecutionException { assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart()); jenkins.getPluginManager().visit("installed"); check(find(by.url("plugin/gerrit-trigger")), false); WebElement form = find(by.action("plugin/gerrit-trigger/uninstall")); form.submit();/* w w w . ja v a2 s . co m*/ jenkins.restart(); jenkins.getPluginManager().visit("installed"); WebElement trigger = find(by.url("plugin/gerrit-trigger")); assertFalse(trigger.isSelected()); }
From source file:core.UninstallPluginTest.java
License:Open Source License
/** * Scenario: Uninstall a plugin (gerrit-trigger), restart jenkins and verify that the plugin is not installed *///from w w w . j a va2 s. com @Test public void gerrit_uninstall_plugin() throws InterruptedException, ExecutionException { jenkins.getPluginManager().visit("installed"); check(find(by.url("plugin/gerrit-trigger")), false); WebElement form = find(by.action("plugin/gerrit-trigger/uninstall")); WebElement uninstall = form.findElement(by.input("Uninstall")); uninstall.click(); jenkins.restart(); Slave s = slaves.install(jenkins).get(); s.waitUntilOnline(); jenkins.getPluginManager().visit("installed"); WebElement trigger = find(by.url("plugin/gerrit-trigger")); assert (!trigger.isSelected()); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckNodeSelectedAction.java
License:Apache License
@Override protected ExecuteResult execute(WebSiteConnector connector) { final WebElementLocator nodeWithVariables = new WebElementLocator(insertVariableValues(node.getSelector()), node.getType());/*w ww . j a v a 2 s . co m*/ try { final WebElement element = connector.getElement(nodeWithVariables); if (element.isSelected()) { LOGGER.info(LoggerMarkers.LEARNER, "Element '{}' is selected.", nodeWithVariables); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Element '{}' is not selected.", nodeWithVariables); return getFailedOutput(); } } catch (NoSuchElementException e) { LOGGER.info(LoggerMarkers.LEARNER, "Could not assert if element '{}' is selected ", nodeWithVariables); return getFailedOutput(); } }
From source file:de.learnlib.alex.data.entities.actions.web.CheckNodeSelectedActionTest.java
License:Apache License
@Test public void shouldReturnOkIfNodeWasFoundAndSelected() { WebElement element = mock(WebElement.class); given(element.isSelected()).willReturn(true); given(webSiteConnector.getElement(node)).willReturn(element); assertTrue(action.executeAction(connectors).isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckNodeSelectedActionTest.java
License:Apache License
@Test public void shouldReturnFailedIfNodeWasFoundAndNotSelected() { WebElement element = mock(WebElement.class); given(element.isSelected()).willReturn(false); given(webSiteConnector.getElement(node)).willReturn(element); assertFalse(action.executeAction(connectors).isSuccess()); }
From source file:DerpSelenium.test.java
public static void info(String name, WebElement element) { print("Element name = " + name); print("Element.isDisplayed = " + element.isDisplayed()); print("Element.isEnabled = " + element.isEnabled()); print("Element.isSeleceted = " + element.isSelected()); }
From source file:dk.netarkivet.systemtest.page.DomainConfigurationPageHelper.java
License:Open Source License
private static void setCheckbox(WebElement checkbox, boolean value) { if ((checkbox.isSelected() && !value) || (!checkbox.isSelected() && value)) { checkbox.click();// w w w . ja v a 2 s . c om } }