org.openqa.selenium.support.ui.Select.getAllSelectedOptions()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.openqa.selenium.support.ui.Select.getAllSelectedOptions()方法的一些代码示例,展示了Select.getAllSelectedOptions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.getAllSelectedOptions()方法的具体详情如下:
包路径:org.openqa.selenium.support.ui.Select
类名称:Select
方法名:getAllSelectedOptions

Select.getAllSelectedOptions介绍

暂无

代码示例

代码示例来源:origin: selenide/selenide

private String getSelectedOptionsTexts(WebElement element) {
 List<WebElement> selectedOptions = new Select(element).getAllSelectedOptions();
 StringBuilder sb = new StringBuilder();
 for (WebElement selectedOption : selectedOptions) {
  sb.append(selectedOption.getText());
 }
 return sb.toString();
}

代码示例来源:origin: selenide/selenide

@Override
public List<WebElement> getElements() {
 return new Select(selectElement.getWebElement()).getAllSelectedOptions();
}

代码示例来源:origin: spring-io/initializr

private Object getInputValue(WebElement input) {
  Object value = null;
  String type = input.getAttribute("type");
  if ("select".equals(input.getTagName())) {
    Select select = new Select(input);
    if (select.isMultiple()) {
      value = select.getAllSelectedOptions().stream().map(this::getValue)
          .collect(Collectors.toList());
    }
    else {
      value = getValue(select.getFirstSelectedOption());
    }
  }
  else if (Arrays.asList("checkbox", "radio").contains(type)) {
    if (input.isSelected()) {
      value = getValue(input);
    }
    else {
      if (Objects.equals(type, "checkbox")) {
        value = false;
      }
    }
  }
  else {
    value = getValue(input);
  }
  return value;
}

代码示例来源:origin: stackoverflow.com

WebElement element = driver.findElement(By.xpath(locator1));
Select select = new Select(element);
List<WebElement> selectedOptions = select.getAllSelectedOptions();
for(WebElement selectedOption : selectedOptions) {
  System.out.println(selectedOption.getText());
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-test-lib

/**
 *
 * @return all selected options
 */
public List<WebElement> getSelectedOptions() {
  Select se = new Select(this);
  return se.getAllSelectedOptions();
}

代码示例来源:origin: qaprosoft/carina

@Override
public String doGetSelectedValue() {
  final Select s = new Select(element);
  return s.getAllSelectedOptions().get(0).getText();
}

代码示例来源:origin: yandex-qatools/htmlelements

/**
 * Returns all selected options belonging to this select tag.
 *
 * @return A list of {@code WebElements} representing selected options.
 */
public List<WebElement> getAllSelectedOptions() {
  return getSelect().getAllSelectedOptions();
}

代码示例来源:origin: ru.sbtqa.htmlelements/htmlelements-java

/**
 * Returns all selected options belonging to this select tag.
 *
 * @return A list of {@code WebElements} representing selected options.
 */
public List<WebElement> getAllSelectedOptions() {
  return getSelect().getAllSelectedOptions();
}

代码示例来源:origin: com.github.wiselenium/wiselenium-elements

@Override
public List<String> getSelectedValues() {
  List<String> values = Lists.newArrayList();
  List<WebElement> selectedOptions = this.getWrappedSelect().getAllSelectedOptions();
  for (WebElement option : selectedOptions)
    values.add(option.getAttribute("value"));
  return values;
}

代码示例来源:origin: com.github.wiselenium/wiselenium-core

@Override
public List<String> getSelectedValues() {
  List<String> values = Lists.newArrayList();
  List<WebElement> selectedOptions = this.getWrappedSelect().getAllSelectedOptions();
  for (WebElement option : selectedOptions)
    values.add(option.getAttribute("value"));
  return values;
}

代码示例来源:origin: com.github.wiselenium/wiselenium-elements

@Override
public List<String> getSelectedVisibleTexts() {
  List<String> texts = Lists.newArrayList();
  List<WebElement> selectedOptions = this.getWrappedSelect().getAllSelectedOptions();
  for (WebElement option : selectedOptions)
    texts.add(option.getText());
  return texts;
}

代码示例来源:origin: com.github.wiselenium/wiselenium-core

@Override
public List<String> getSelectedVisibleTexts() {
  List<String> texts = Lists.newArrayList();
  List<WebElement> selectedOptions = this.getWrappedSelect().getAllSelectedOptions();
  for (WebElement option : selectedOptions)
    texts.add(option.getText());
  return texts;
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public List<WebElement> getDropdownSelectedOptions(WebElement element) {
  try {
    return driverDropdown(element).getAllSelectedOptions();
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: ru.yandex.qatools.htmlelements/htmlelements-java

/**
 * Returns all selected options belonging to this select tag.
 *
 * @return A list of {@code WebElements} representing selected options.
 */
public List<WebElement> getAllSelectedOptions() {
  return getSelect().getAllSelectedOptions();
}

代码示例来源:origin: sayems/java.webdriver

public List<String> getAllSelectedValues(Supplier<By> by) {
  return new Select(findElement(by)).getAllSelectedOptions()
      .stream()
      .map(option -> option.getAttribute(VALUE))
      .collect(Collectors.toList());
}

代码示例来源:origin: qaprosoft/carina

@Override
public List<String> doGetSelectedValues() {
  final Select s = new Select(getElement());
  List<String> values = new ArrayList<String>();
  for (WebElement we : s.getAllSelectedOptions()) {
    values.add(we.getText());
  }
  return values;
}

代码示例来源:origin: stackoverflow.com

Select dropdown = new Select(driver.findElement(By.id("competitiveCategoryTemp")));

dropdown.getOptions()  // will return all the options - it is a List<WebElement>

//To use
for(WebElement option: dropdown.getOptions()){
  System.out.println(option.getText());
}

dropdown.getAllSelectedOptions() // will return the default selected options - it is a List<WebElement>

代码示例来源:origin: net.serenity-bdd/serenity-core

public Set<String> getSelectedOptionLabels() {
  List<WebElement> options = new Select(dropdownField).getAllSelectedOptions();
  Set<String> selectedOptions = new HashSet<>();
  for (WebElement option : options) {
    if (option.isSelected()) {
      selectedOptions.add(option.getText());
    }
  }
  return selectedOptions;
}

代码示例来源:origin: com.epam.jdi/jdi-light

@JDIAction("Get checked elements")
public List<String> checked() {
  return map(select().getAllSelectedOptions(), WebElement::getText);
}
@JDIAction("Get selected value")

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-test-lib

/**
 *
 * @return all selected options
 */
public List<WebElement> getSelectedOptions() {
  if (isReadOnly()) {
    return getOptions();
  }
  WebElement input = getInputField();
  Select se = new Select(input);
  return se.getAllSelectedOptions();
}

相关文章