无法处理报告中的下拉选择

时间:2015-02-02 03:18:28

标签: selenium-webdriver

我正在尝试修改以下报告代码。这用于根据脚本中使用的命令在selenium中进行报告(例如:单击复选框,图像,单选按钮等)。当selenium脚本具有" Select"用于处理dropdownn的类。你能否帮我修改下面的代码来处理报告部分中的下拉选择。

public void click(){
    String name = ""; String strObjectType = "";

    if(this.globalObject.webElementCondition==true){

        if (this.getAttribute("type")!=null && (this.getAttribute("type").equalsIgnoreCase("submit")|| this.getAttribute("type").equalsIgnoreCase("button"))){
          name=this.getAttribute("value");
          if (name.trim().equals("")) {
              name=this.getText();
          }          
          strObjectType = "button";
        }else if (this.getTagName().equalsIgnoreCase("a")){
          name=this.getText();
          strObjectType = "hyperlink";
        }else if (this.getTagName().equalsIgnoreCase("img")){
          //name=this.getAttribute("src");
          String[] ImgName = this.getAttribute("src").split("/");
          name = ImgName[ImgName.length-1];
          strObjectType = "Image link";
        }else if (this.getAttribute("name")!=null&&!this.getAttribute("name").equals("")){
          name=this.getAttribute("name");
          strObjectType = "text/lable";
        }else if (this.getAttribute("id")!=null&&!this.getAttribute("id").equals("")){
              name=this.getAttribute("id");
        }else if (this.getAttribute("value")!=null&&!this.getAttribute("value").equals("")){
          name=this.getAttribute("value"); 
        } 
        //System.out.println("Name : "+name);
        try
        {   
            execute(DriverCommand.CLICK_ELEMENT, ImmutableMap.of("id", id));

            this.globalObject.reporting.WriteStep("Pass", "Click on ["+name+"] "+ strObjectType , "User should be able to click on ["+name+"] "+ strObjectType, "Clicked on ["+name+"] " + strObjectType);
        }catch(Exception e)
        {   this.globalObject.TestStepStatus="Fail";
            this.globalObject.reporting.WriteStep("Fail", "Click on ["+name+"] "+ strObjectType , "User should be able to click on ["+name+"] " + strObjectType, "Not Clicked on ["+name+"] "+ strObjectType);
        }
    }   
}

0 个答案:

没有答案