/** * 获取选项列表 * * @return */ public List<WebElement> getOptions() { return this.findElements(By.tagName("option")); } /** * 根据select的value来选择 * * @param value */ public void setOptionByValue(String value) { for (WebElement op : getOptions()) { if (op.getAttribute("value").equals(value)) { op.click(); return; } } throw new NoSuchElementException( "Cannot locate an element in Select-setOptionByValue "); } /** * 根据显示的文本来选择 * * @param text */ public void setOptionByText(String text) { for (WebElement op : getOptions()) { if (op.getText().equals(text)) { op.click(); return; } } throw new NoSuchElementException( "Cannot locate an element in Select-setOptionByText "); }
更多资料关注:www.kootest.com ;技术交流群:182526995