Package daveayan.gherkinsalad.components.html

Source Code of daveayan.gherkinsalad.components.html.DropDown

package daveayan.gherkinsalad.components.html;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.By;

import daveayan.gherkinsalad.components.Element;
import daveayan.gherkinsalad.components.Elements;
import daveayan.gherkinsalad.components.Selectable;

public class DropDown extends BaseBrowserElement implements Selectable {
 
  public static DropDown find(By locator) {
    DropDown d = new DropDown();
    d.found(locator);
    return d;
  }
 
  public DropDown name(String name) {
    super.name(name);
    return this;
  }
 
  public boolean isEnabled() {
    Element element = root_element();
    return element.isEnabled();
  }

  public void select_option_if_enabled(String option) {
    Element element = root_element();
    if(this.isEnabled()) {
      Elements options = element.findElements(By.tagName("option"));
      Element option_to_select = options.findFirstElementWithText(option);
      option_to_select.click();
    }
  }
 
  public void select_code_if_enabled(String code) {
    Element element = root_element();
    if(this.isEnabled()) {
      Elements options = element.findElements(By.tagName("option"));
      for(Element o: options._nativeList()) {
        if(StringUtils.equals(o.getAttribute("value"), code)) {
          o.click();
          break;
        }
      }
    }
  }

  public void should_have_options(String... options) {
    throw new AssertionError("DropDown::has_options(" + options + ") is not implemented yet");
  }

  public List<String> get_all_options() {
    // TODO Auto-generated method stub
    return null;
  }
}
TOP

Related Classes of daveayan.gherkinsalad.components.html.DropDown

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.