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

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

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

Select.getFirstSelectedOption介绍

暂无

代码示例

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

WebElement select = driver.findElement(By.name("myselect"));
Select dropDown = new Select(select);           
String selected = dropDown.getFirstSelectedOption().getText();
if(selected.equals(valueToSelect)){
  //already selected; 
  //do stuff
}
List<WebElement> Options = dropDown.getOptions();
for(WebElement option:Options){
  if(option.getText().equals(valueToSelect)) {
   option.click(); //select option here;       
  }               
}

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

@Override
 public SelenideElement execute(SelenideElement proxy, WebElementSource selectElement, Object[] args) {
  return wrap(selectElement.driver(), new Select(selectElement.getWebElement()).getFirstSelectedOption());
 }
}

代码示例来源: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: TEAMMATES/teammates

private String getGenerateOptionsForMsqValue(int qnNumber) {
  Select options = new Select(browser.driver.findElement(By.id("msqGenerateForSelect-" + qnNumber)));
  return options.getFirstSelectedOption().getText();
}

代码示例来源:origin: TEAMMATES/teammates

public String getDropdownSelectedValue(WebElement element) {
  Select select = new Select(element);
  return select.getFirstSelectedOption().getAttribute("value");
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Selects the option by visible text and returns whether the dropdown value has changed.
 *
 * @throws AssertionError if the selected option is not the one we wanted to select
 *
 * @see Select#selectByVisibleText(String)
 */
boolean selectDropdownByVisibleValue(WebElement element, String text) {
  Select select = new Select(element);
  WebElement originalSelectedOption = select.getFirstSelectedOption();
  select.selectByVisibleText(text);
  WebElement newSelectedOption = select.getFirstSelectedOption();
  assertEquals(text, newSelectedOption.getText().trim());
  return !newSelectedOption.equals(originalSelectedOption);
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Selects the option by value and returns whether the dropdown value has changed.
 *
 * @throws AssertionError if the selected option is not the one we wanted to select
 *
 * @see Select#selectByValue(String)
 */
boolean selectDropdownByActualValue(WebElement element, String value) {
  Select select = new Select(element);
  WebElement originalSelectedOption = select.getFirstSelectedOption();
  select.selectByValue(value);
  WebElement newSelectedOption = select.getFirstSelectedOption();
  assertEquals(value, newSelectedOption.getAttribute("value"));
  return !newSelectedOption.equals(originalSelectedOption);
}

代码示例来源:origin: TEAMMATES/teammates

public int getSelectedQuestionNumber(int qnNumber) {
  if (isQuestionEnabled(qnNumber)) {
    Select qnNumSelect = new Select(getSelectQuestionNumberDropdown(qnNumber));
    return Integer.parseInt(qnNumSelect.getFirstSelectedOption().getText().trim());
  }
  //substring trims colon from the retrieved question number text
  String questionNumber = getSelectQuestionNumberStatic(qnNumber).getText();
  return Integer.parseInt(questionNumber.substring(0, questionNumber.length() - 1));
}

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

@JDIAction("Get selected value")
public String selected() {
  return select().getFirstSelectedOption().getText();
}
@JDIAction("Is '{0}' selected")

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

public String getFirstSelectedText(Supplier<By> by) {
  try {
    return new Select(findElement(by)).getFirstSelectedOption().getText();
  } catch (NoSuchElementException e) {
    return null;
  }
}

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

public Integer getFirstSelectedIndex(Supplier<By> by) {
  try {
    Select select = new Select(findElement(by));
    List<WebElement> options = select.getOptions();
    if (!options.isEmpty()) {
      return options.indexOf(select.getFirstSelectedOption());
    }
    return null;
  } catch (NoSuchElementException e) {
    return null;
  }
}

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

@Override
public String getSelectedValue() {
  waitUntilVisible();
  Select select = new Select(getElement());
  return select.getFirstSelectedOption().getAttribute("value");
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

/**
 * @return the selected year
 */
public String getYear()
{
  Select yearSelector = new Select(container.findElement(By.className("year")));
  return yearSelector.getFirstSelectedOption().getText();
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

/**
 * @return the selected month
 */
public String getMonth()
{
  Select monthSelector = new Select(container.findElement(By.className("month")));
  return monthSelector.getFirstSelectedOption().getText();
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

/**
 * @return the selected minute
 */
public String getMinute()
{
  Select minuteSelector = new Select(container.findElement(By.className("minute")));
  return minuteSelector.getFirstSelectedOption().getText();
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-test-ui

/**
 * @return the selected hour
 */
public String getHour()
{
  Select hourSelector = new Select(container.findElement(By.className("hour")));
  return hourSelector.getFirstSelectedOption().getText();
}

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

public J getSelectedOption() throws NoSuchElementException {
  Select selectField = new Select(getWebElement());
  WebElement selectedOption = selectField.getFirstSelectedOption();
  return new J(selectedOption);
}

代码示例来源:origin: epam/JDI

public J getSelectedOption() throws NoSuchElementException {
  Select selectField = new Select(getWebElement());
  WebElement selectedOption = selectField.getFirstSelectedOption();
  return new J(selectedOption);
}

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

protected String getTextAction() {
  String result = "";
  if (element().getLocator().toString().contains("select")) try {
    result = new Select(element().getWebElement()).getFirstSelectedOption().getText();
  } catch (Exception ignore) {}
  return result != null && !result.equals("")
    ? result
    : element().getText();
}

代码示例来源:origin: epam/JDI

protected String getTextAction() {
  String result = "";
  if (root().getLocator().toString().contains("select")) try {
    result = new Select(root().getWebElement()).getFirstSelectedOption().getText();
  } catch (Exception ignore) {}
  return result != null && !result.equals("")
    ? result
    : input().getText();
}

相关文章