小代码改进

小代码改进

 package MonitorTest; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; public class MonitorTest_improve {  public static void main(String[] args) throws InterruptedException, IOException{   //存储监控 名称的文件地址   String fileUrl="D:\\bukejian\\tmp.txt";   //访问地址   String url=;   ArrayList<String> list = new ArrayList<String>();   String encoding="GBK";      File file = new File(fileUrl);   if(file.isFile() && file.exists()){             InputStreamReader read = new InputStreamReader(             new FileInputStream(file),encoding);             BufferedReader bufferedReader = new BufferedReader(read);             String lineTxt = null;             while((lineTxt = bufferedReader.readLine()) != null){                list.add(lineTxt);             }             read.close();          }else{           System.out.println("No exist");          }             System.setProperty("webdriver.firefox.bin", "D:/bukejian/Mozilla Firefox/firefox.exe");   WebDriver dr = new FirefoxDriver();    dr.get(url);   WebElement submit=(new WebDriverWait(dr,10)).until(new ExpectedCondition<WebElement>(){       @Override       public WebElement apply(WebDriver d){        return d.findElement(By.cssSelector("input[type=\"submit\"]"));       }      });   dr.findElement(By.name("login_username")).clear();   dr.findElement(By.name("login_username")).sendKeys("bukejian");   dr.findElement(By.name("login_password")).clear();   dr.findElement(By.name("login_password")).sendKeys("bukejian");   submit.click();      int j=0;   for(String a :list){    (new WebDriverWait(dr,10)).until(new ExpectedCondition<WebElement>(){        @Override        public WebElement apply(WebDriver d){         return d.findElement(By.linkText("Add"));        }       }).click();        WebElement select=(new WebDriverWait(dr,10)).until(new ExpectedCondition<WebElement>(){        @Override        public WebElement apply(WebDriver d){         return d.findElement(By.name("type_select"));        }       });    new Select(select).selectByVisibleText("Graph");        WebElement graph_id=(new WebDriverWait(dr,10)).until(new ExpectedCondition<WebElement>(){        @Override        public WebElement apply(WebDriver d){         return d.findElement(By.id("local_graph_id"));        }       });       new Select(graph_id).selectByVisibleText(a);              (new WebDriverWait(dr,10)).until(new ExpectedCondition<WebElement>(){        @Override        public WebElement apply(WebDriver d){         return d.findElement(By.cssSelector("input[type=\"button\"]"));        }       }).click();                     //dr.findElement(By.cssSelector("input[type=\"submit\"]")).click();//提交                  System.out.println(j+"="+a);       j++;       }   dr.close();    } }

全加上了 等待10s,用取消操作验证了下倒是不会超时报错了

Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”bukejian”,”selector”:”bukejian”}

之前会报这种错误,应该是没找到元素超时了,这次所有元素都最多等待10s应该不会报错了吧

转载于:https://my.oschina.net/u/571166/blog/273048

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109810.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Spring整合Mybatis注解方式

    Spring整合Mybatis注解方式Spring整合Mybatis(注解方式)目录Spring整合Mybatis(注解方式)环境准备纯注解方式配置类具体内容测试类具体内容环境准备jar包:Spring所需依赖:spring-context、spring-aspects、aspectjrt、aspectjweaver、spring-tx、spring-jdbcmybatis所需要:mybatis、mybatis-spring、mysql-connector-java、(druid、c3p0、HikariCP)辅

    2022年5月1日
    49
  • double类型转换成int类型

    publicclasstest09{publicstaticvoidmain(String[]args){doublea=5000.44;doubleb=100.12;doublev=a/b;inti=newDouble(v).intValue();…

    2022年4月5日
    86
  • java变量设置_如何正确的配置JAVA环境变量

    java变量设置_如何正确的配置JAVA环境变量原创:YiKiA2Data什么是环境变量?环境变量是在操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息。为什么要配置环境变量?为了方便在控制台编译和运行java程序,不必进入到java的程序目录里面去运行。这样你放在任何目录下的java程序文件都可以编译运行,而不是必须把这个程序文件放在java.exe和javac.exe所在的目录下。什么是JAVA_HOME…

    2022年7月7日
    24
  • 什么是RESTful API

    什么是RESTful API

    2021年11月6日
    39
  • 2021 idea激活码最新(破解版激活)

    2021 idea激活码最新(破解版激活),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月17日
    66
  • ireport 分页_sql组内分组

    ireport 分页_sql组内分组1、创建订单表et_order,并插入数据2.创建订单明细表et_order_detail,并插入数据3.不分组显示,将字段放入detail部分预览效果4.按照订单ID分组打印报表展示,点击模板名称,然后右键选择addreportgroup5.创建分组名称和分组字段6.分组包含了3部分,头部。明细。尾部,标题想要每张纸都显示,则需要放在pageheader块中7.最终效果…完美的达到了自己需要的效果。…

    2022年9月10日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号