List of usage examples for org.openqa.selenium WebElement isSelected
boolean isSelected();
From source file:com.comcast.dawg.house.pages.IndexPage.java
License:Apache License
/** * Select all of the stb check boxes./* www . j a v a2s . c om*/ */ public void selectAllStbCheckbox() { WebElement toggleButton = getToggleAllCheckboxElement(); if (!toggleButton.isSelected()) { toggleButton.click(); } }
From source file:com.comcast.dawg.house.pages.ModelPage.java
License:Apache License
/** * Selecting an already available capability check box on loaded model overlay. * * @param capability Capability to be selected. *//*from w w w. ja v a2 s . c o m*/ private void selectCapabilityOnAlreadyLoadedModelOverlay(String capability) { WebElement capabilityCheckBox = getCapabilityElementOnAlreadyLoadedModelOverlay(capability); if (capabilityCheckBox.isSelected()) { capabilityCheckBox.click(); } }
From source file:com.common.ExpectedConditions.java
License:Apache License
/** * An expectation for checking if the given element is selected. * * @param element WebElement to be selected * @param selected boolean state of the selection state of the element * @return true once the element's selection stated is that of selected *///from w ww . j a v a2s .co m public static ExpectedCondition<Boolean> elementSelectionStateToBe(final WebElement element, final boolean selected) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { return element.isSelected() == selected; } @Override public String toString() { return String.format("element (%s) to %sbe selected", element, (selected ? "" : "not ")); } }; }
From source file:com.common.ExpectedConditions.java
License:Apache License
public static ExpectedCondition<Boolean> elementSelectionStateToBe(final By locator, final boolean selected) { return new ExpectedCondition<Boolean>() { @Override// w w w . j a v a 2 s . c om public Boolean apply(WebDriver driver) { try { WebElement element = driver.findElement(locator); return element.isSelected() == selected; } catch (StaleElementReferenceException e) { return null; } } @Override public String toString() { return String.format("element found by %s to %sbe selected", locator, (selected ? "" : "not ")); } }; }
From source file:com.consol.citrus.selenium.actions.CheckInputAction.java
License:Apache License
@Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); if (webElement.isSelected() && !checked) { webElement.click();//ww w.j a va2 s . com } else if (checked && !webElement.isSelected()) { webElement.click(); } }
From source file:com.consol.citrus.selenium.actions.DropDownSelectActionTest.java
License:Apache License
@Test public void testExecuteSelect() throws Exception { WebElement option = Mockito.mock(WebElement.class); when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.findElements(any(By.class))).thenReturn(Collections.singletonList(option)); when(option.isSelected()).thenReturn(false); action.setOption("select_me"); action.execute(context);// w w w . j a v a 2 s .co m verify(option).click(); }
From source file:com.consol.citrus.selenium.actions.DropDownSelectActionTest.java
License:Apache License
@Test public void testExecuteMultiSelect() throws Exception { WebElement option = Mockito.mock(WebElement.class); seleniumBrowser.getEndpointConfiguration().setBrowserType(BrowserType.IE); when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.findElements(any(By.class))).thenReturn(Collections.singletonList(option)); when(option.isSelected()).thenReturn(false); action.setOptions(Arrays.asList("option1", "option2")); action.execute(context);/* w w w . j a v a 2 s. c om*/ verify(option, times(2)).click(); }
From source file:com.consol.citrus.selenium.actions.SetInputActionTest.java
License:Apache License
@Test public void testExecuteOnSelect() throws Exception { WebElement option = Mockito.mock(WebElement.class); when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.getTagName()).thenReturn("select"); when(element.findElements(any(By.class))).thenReturn(Collections.singletonList(option)); when(option.isSelected()).thenReturn(false); action.setValue("option"); action.execute(context);//from w w w. ja v a 2 s .com verify(option).click(); }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
/** * Enable or disable a check button./*from w w w. j ava2 s . co m*/ * * @param by * @param str "true" or "false". */ public void checkItem(By by, String str) { boolean value = Boolean.parseBoolean(str); WebElement element = findElement(by); if (element.isSelected() && !value) { element.click(); } else if (value && !element.isSelected()) { element.click(); } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
/** * Select multiple items from a pull-down list. * * @param by// w w w. j a v a 2s .c o m * @param from Start at index. * @param to End at index. */ public void selectMultipleItems(By by, int from, int to) { Select dropdown = new Select(findElement(by)); if (BrowserTypeEnum.INTERNET_EXPLORER.equals(browserType)) { for (int i = from; i < to; i++) { dropdown.selectByIndex(i); } } else { //Rest: List<WebElement> options = dropdown.getOptions(); Actions builder = new Actions(webDriver); builder.keyDown(Keys.CONTROL); for (int i = from; i < to; i++) { WebElement item = options.get(i); if (!item.isSelected()) { builder.moveToElement(item).click(item); } } builder.keyUp(Keys.CONTROL); Action multiple = builder.build(); multiple.perform(); } }