zoukankan      html  css  js  c++  java
  • Selenium webdriver 之select 控件封装,解决onchange问题

    使用webdriver的时候,select 控件经常会绑定onchange 事件,在selenium2.09 之前click 方法对onchange 事件有bug,2.09 以后修复了,但是根据经验也遇到用selenium ui 下面的select的类去做select 操作,有时也可能不发触发onchange 事件,所以本人测试放弃不用,自己封装了几个好用的方法,在此分享,部分只要实现代码如下: 

    /**
    * 获取选项列表
    * 
    * @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

  • 相关阅读:
    node.js的querystring模块
    jsonp的作用
    js开发性能(一)
    express创建第一个web应用
    安装express
    关于【歧视】的一点事
    在统计报表中用到的sql语法记录
    北京民航总医院杀医事件
    那些自杀的人似乎更有勇气
    河南人究竟偷了多少井盖?
  • 原文地址:https://www.cnblogs.com/kootest/p/4088121.html
Copyright © 2011-2022 走看看