コード例 #1
0
ファイル: Select.java プロジェクト: ZouYu99/selenium
  /**
   * Select all options that display text matching the argument. That is, when given "Bar" this
   * would select an option like:
   *
   * <p>&lt;option value="foo"&gt;Bar&lt;/option&gt;
   *
   * @param text The visible text to match against
   * @throws NoSuchElementException If no matching option elements are found
   */
  public void selectByVisibleText(String text) {
    // try to find the option via XPATH ...
    List<WebElement> options =
        element.findElements(
            By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));

    boolean matched = false;
    for (WebElement option : options) {
      setSelected(option, true);
      if (!isMultiple()) {
        return;
      }
      matched = true;
    }

    if (options.isEmpty() && text.contains(" ")) {
      String subStringWithoutSpace = getLongestSubstringWithoutSpace(text);
      List<WebElement> candidates;
      if ("".equals(subStringWithoutSpace)) {
        // hmm, text is either empty or contains only spaces - get all options ...
        candidates = element.findElements(By.tagName("option"));
      } else {
        // get candidates via XPATH ...
        candidates =
            element.findElements(
                By.xpath(".//option[contains(., " + Quotes.escape(subStringWithoutSpace) + ")]"));
      }
      for (WebElement option : candidates) {
        if (text.equals(option.getText())) {
          setSelected(option, true);
          if (!isMultiple()) {
            return;
          }
          matched = true;
        }
      }
    }

    if (!matched) {
      throw new NoSuchElementException("Cannot locate element with text: " + text);
    }
  }
コード例 #2
0
ファイル: Select.java プロジェクト: ZouYu99/selenium
  /**
   * Deselect all options that have a value matching the argument. That is, when given "foo" this
   * would deselect an option like:
   *
   * <p>&lt;option value="foo"&gt;Bar&lt;/option&gt;
   *
   * @param value The value to match against
   * @throws NoSuchElementException If no matching option elements are found
   * @throws UnsupportedOperationException If the SELECT does not support multiple selections
   */
  public void deselectByValue(String value) {
    if (!isMultiple()) {
      throw new UnsupportedOperationException("You may only deselect options of a multi-select");
    }

    List<WebElement> options =
        element.findElements(By.xpath(".//option[@value = " + Quotes.escape(value) + "]"));
    boolean matched = false;
    for (WebElement option : options) {
      setSelected(option, false);
      matched = true;
    }
    if (!matched) {
      throw new NoSuchElementException("Cannot locate option with value: " + value);
    }
  }
コード例 #3
0
ファイル: Select.java プロジェクト: ZouYu99/selenium
  /**
   * Select all options that have a value matching the argument. That is, when given "foo" this
   * would select an option like:
   *
   * <p>&lt;option value="foo"&gt;Bar&lt;/option&gt;
   *
   * @param value The value to match against
   * @throws NoSuchElementException If no matching option elements are found
   */
  public void selectByValue(String value) {
    List<WebElement> options =
        element.findElements(By.xpath(".//option[@value = " + Quotes.escape(value) + "]"));

    boolean matched = false;
    for (WebElement option : options) {
      setSelected(option, true);
      if (!isMultiple()) {
        return;
      }
      matched = true;
    }

    if (!matched) {
      throw new NoSuchElementException("Cannot locate option with value: " + value);
    }
  }
コード例 #4
0
ファイル: Select.java プロジェクト: ZouYu99/selenium
  /**
   * Deselect all options that display text matching the argument. That is, when given "Bar" this
   * would deselect an option like:
   *
   * <p>&lt;option value="foo"&gt;Bar&lt;/option&gt;
   *
   * @param text The visible text to match against
   * @throws NoSuchElementException If no matching option elements are found
   * @throws UnsupportedOperationException If the SELECT does not support multiple selections
   */
  public void deselectByVisibleText(String text) {
    if (!isMultiple()) {
      throw new UnsupportedOperationException("You may only deselect options of a multi-select");
    }

    List<WebElement> options =
        element.findElements(
            By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));

    boolean matched = false;
    for (WebElement option : options) {
      setSelected(option, false);
      matched = true;
    }

    if (!matched) {
      throw new NoSuchElementException("Cannot locate element with text: " + text);
    }
  }
コード例 #5
0
 public boolean isNotLast() {
   return getNumber() != quotes.size();
 }
コード例 #6
0
 boolean hasAtLeastTwoQuote() {
   return quotes.size() > 1;
 }
コード例 #7
0
 private List<Quote> quotes() {
   return quotes.getQuotes();
 }