Example usage for org.openqa.selenium.support.ui Select getAllSelectedOptions

List of usage examples for org.openqa.selenium.support.ui Select getAllSelectedOptions

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui Select getAllSelectedOptions.

Prototype

@Override
public List<WebElement> getAllSelectedOptions() 

Source Link

Usage

From source file:applicationdriverlayer.pageobjects.squash.booking.CourtAndTimeSlotChooserPage.java

License:Apache License

public java.time.LocalDate getDate() {
    // Read the date from the DateDropdown
    Select dateSelect = new Select(dateDropdown);
    // datePage will be like '2015-12-23.html'
    String datePage = dateSelect.getAllSelectedOptions().get(0).getAttribute("value");
    // Strip html suffix
    String trimmedDatePage = datePage.substring(0, datePage.indexOf(".html"));
    return java.time.LocalDate.parse(trimmedDatePage);
}

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static Select getRefreshedBlockSelect(WebDriver driver, int districtIndex) {

    Select districtSelect = new Select(driver.findElement(By.name(Constants.DDL_DISTRICT)));
    districtSelect.selectByIndex(districtIndex);

    if (logger.isDebugEnabled()) {

        logger.debug("getRefreshedBlockSelect(WebDriver, int) - selected district="
                + districtSelect.getAllSelectedOptions().toString()); //$NON-NLS-1$
    }//from   w ww  .j  ava 2  s. com

    waitForBlock(driver, getDistrictValueFromIndex(districtIndex), Constants.SELECT_0);
    Select blockSelect = new Select(driver.findElement(By.name(Constants.DDL_BLOCK)));

    return blockSelect;
}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public boolean isDropDownSelectedText(Select selectElement, String text) {
    List<WebElement> selectedOptions = selectElement.getAllSelectedOptions();
    for (WebElement option : selectedOptions) {
        if (option.getText().equals(text))
            return true;
    }/*from www. j a  va 2s .  c  om*/
    return false;
}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public boolean isDropDownSelectedValue(Select selectElement, String value) {
    List<WebElement> selectedOptions = selectElement.getAllSelectedOptions();
    for (WebElement option : selectedOptions) {
        if (option.getAttribute("value").equals(value))
            return true;
    }//from   www.  j a  va2s .  co  m
    return false;
}

From source file:com.hotwire.selenium.desktop.us.billing.air.AirPassengerInfoFragment.java

License:Open Source License

public AirPassengerInfoFragment fillPassengerName(int i, String firstName, String middleName, String lastName) {

    String passengerName = getPassengerFullNameAsString(firstName, middleName, lastName);
    LOGGER.info("Trying to fill passenger information about {}", passengerName);

    WebElement existsTravelerDropdown = selectExistsPassengerByIndex(i);
    WebElement travelerFirstNameInput = getPassengerFirstNameByIndex(i);

    if (existsTravelerDropdown != null) {
        LOGGER.info("Search for traveler from dropdown list of exists persons..");
        Select passNameList = new Select(existsTravelerDropdown);
        List<WebElement> passNameListElements = passNameList.getAllSelectedOptions();

        if (passNameListElements.contains(passengerName)) {
            LOGGER.info("Traveler is found and selected..");
            selectByText(existsTravelerDropdown, passengerName);
            return this;
        } else {/*from   ww  w  . java 2 s  .  com*/
            LOGGER.info("Traveler is not found..");
            createNewPassenger(firstName, lastName, middleName, i);
            return this;
        }
    } else if (travelerFirstNameInput != null) {
        LOGGER.info("Fill in traveler first, last and middle names into fields..");
        sendKeys(travelerFirstNameInput, firstName);
        sendKeys(getPassengerLastNameByIndex(i), lastName);
        sendKeys(getPassengerMiddleNameByIndex(i), middleName);
    } else {
        throw new RuntimeException("Can't fill the first, last or middle names of traveler..");
    }
    return this;
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static String[] getSelectedLabels(WebDriver webDriver, String selectLocator) {

    WebElement selectLocatorWebElement = getWebElement(webDriver, selectLocator);

    Select select = new Select(selectLocatorWebElement);

    List<WebElement> allSelectedOptionsWebElements = select.getAllSelectedOptions();

    String[] selectedOptionsWebElements = new String[allSelectedOptionsWebElements.size()];

    for (int i = 0; i < allSelectedOptionsWebElements.size(); i++) {
        WebElement webElement = allSelectedOptionsWebElements.get(i);

        if (webElement != null) {
            selectedOptionsWebElements[i] = webElement.getText();
        }//w  ww . ja v  a2  s .co  m
    }

    return selectedOptionsWebElements;
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckSelectOptionTextCommand.java

License:Apache License

@Override
protected void doOperationOnElement(WebElement elem) {

    if (!CommandUtils.checkIfElementIsSelect(elem)) {
        fail("Element expected to be a SELECT");
    }/*from w  ww.  ja v a 2  s.c  om*/

    Select select = new Select(elem);

    selectOptions = select.getOptions();

    allSelectedOptions = select.getAllSelectedOptions();

    AbstractCheck checkLogic = defineCheckLogic();

    expectedSelectText = parameterMap.get(selectedTextParam);

    checkLogic.runStandardCommand();

}

From source file:com.screenslicer.core.scrape.QueryForm.java

License:Open Source License

public static void perform(RemoteWebDriver driver, FormQuery context) throws ActionFailed {
    try {//  w ww  .  java  2  s .co  m
        Util.get(driver, context.site, true);
        Util.doClicks(driver, context.preAuthClicks, null);
        QueryCommon.doAuth(driver, context.credentials);
        Util.doClicks(driver, context.preSearchClicks, null);
        Map<String, HtmlNode> formControls = new HashMap<String, HtmlNode>();
        for (int i = 0; i < context.formSchema.length; i++) {
            formControls.put(context.formSchema[i].guid, context.formSchema[i]);
        }
        Map<String, List<String>> formData = context.formModel;
        boolean valueChanged = false;
        int count = 0;
        final int MAX_TRIES = 3;
        Element body = Util.openElement(driver, null, null, null);
        do {
            ++count;
            valueChanged = false;
            for (Map.Entry<String, List<String>> entry : formData.entrySet()) {
                try {
                    HtmlNode formControl = formControls.get(entry.getKey());
                    if (!CommonUtil.isEmpty(entry.getValue())) {
                        if ("select".equalsIgnoreCase(formControl.tagName)) {
                            if (WebApp.DEBUG) {
                                System.out.println("Query Form: select");
                            }
                            Select select = new Select(Util.toElement(driver, formControl, body));
                            if (select.isMultiple()) {
                                select.deselectAll();
                            }
                            List<WebElement> selectedElements = select.getAllSelectedOptions();
                            List<String> selectedStrings = new ArrayList<String>();
                            for (WebElement selectedElement : selectedElements) {
                                String selectedString = selectedElement.getAttribute("value");
                                if (!CommonUtil.isEmpty(selectedString)) {
                                    selectedStrings.add(selectedString);
                                }
                            }
                            boolean matches = true;
                            for (String selectedString : selectedStrings) {
                                if (!entry.getValue().contains(selectedString)) {
                                    matches = false;
                                    break;
                                }
                            }
                            if (!matches || selectedStrings.size() != entry.getValue().size()) {
                                for (String val : entry.getValue()) {
                                    valueChanged = true;
                                    select.selectByValue(val);
                                    Util.driverSleepVeryShort();
                                }
                            }
                        } else if ("input".equalsIgnoreCase(formControl.tagName)
                                && ("text".equalsIgnoreCase(formControl.type)
                                        || "search".equalsIgnoreCase(formControl.type))) {
                            if (WebApp.DEBUG) {
                                System.out.println("Query Form: input[text|search]");
                            }
                            WebElement element = Util.toElement(driver, formControl, body);
                            valueChanged = QueryCommon.typeText(driver, element, entry.getValue().get(0), true,
                                    false);
                        } else if ("input".equalsIgnoreCase(formControl.tagName)
                                && ("checkbox".equalsIgnoreCase(formControl.type)
                                        || "radio".equalsIgnoreCase(formControl.type))) {
                            if (WebApp.DEBUG) {
                                System.out.println("Query Form: input[checkbox|radio]");
                            }
                            WebElement element = Util.toElement(driver, formControl, body);
                            if (entry.getValue() != null && !entry.getValue().isEmpty()) {
                                if ("radio".equalsIgnoreCase(formControl.type)) {
                                    String elementVal = element.getAttribute("value");
                                    String schemaVal = formControl.value;
                                    String modelVal = entry.getValue().get(0);
                                    if (elementVal != null && schemaVal != null
                                            && elementVal.equalsIgnoreCase(schemaVal)
                                            && modelVal.equalsIgnoreCase(schemaVal)) {
                                        if (!element.isSelected()) {
                                            if (WebApp.DEBUG) {
                                                System.out.println("Clicking radio button");
                                            }
                                            valueChanged = Util.click(driver, element);
                                        }
                                    }
                                } else if (!element.isSelected()) {
                                    if (WebApp.DEBUG) {
                                        System.out.println("Clicking [checkbox|radio]");
                                    }
                                    valueChanged = Util.click(driver, element);
                                }
                            } else {
                                if (element.isSelected()) {
                                    if (WebApp.DEBUG) {
                                        System.out.println("Deselecting [checkbox|radio]");
                                    }
                                    valueChanged = true;
                                    element.clear();
                                    Util.driverSleepVeryShort();
                                }
                            }
                        }
                    }
                } catch (Throwable t) {
                    Log.exception(t);
                }
            }
        } while (valueChanged && count < MAX_TRIES);
        doSubmit(driver, context.formId);
        Util.doClicks(driver, context.postSearchClicks, null);
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:com.sinet.gage.uitest.helper.CommonHelper.java

/**
 * Get All selected options/*from   w  ww . ja va 2 s  . c o  m*/
 * 
 * @param element select element
 * @return List of string, selected options
 */
public static List<String> getAllSelectedOptionsFromSelectBox(WebElement element) {
    Select selEle = new Select(element);
    return getTextFromElements(selEle.getAllSelectedOptions());
}

From source file:com.vaadin.tests.components.listselect.ListSelectPushSelectionChangesTest.java

License:Apache License

private List<WebElement> getSelectedOptions() {
    ListSelectElement listSelect = getListSelect();
    Select select = new Select(listSelect.findElement(By.tagName("select")));
    return select.getAllSelectedOptions();
}