小代码改进

小代码改进

 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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • ods mysql_ODS数据抽取平台[通俗易懂]

    ods mysql_ODS数据抽取平台[通俗易懂]一、产品简介ODS数据抽取平台是数据仓库对数据进行精细加工的中间环节,将加工后的数据存储到ODS数据模型中,以便总账,报表,数据仓库使用。将远程网络生产数据库中的数据备份到一台备份机中(防止对生产数据的误操作),然后在可视化的第三方ETL工具中编辑ETL脚本,对备份库中的数据进行精细的加工,ETL脚本可以对网络中的任意一台数据库中任意的一张或多张表进行复杂的计算,然后将计算结果保存到ODS的数据模…

    2022年9月26日
  • python 面向对象(进阶篇)

    python 面向对象(进阶篇)上一篇《Python面向对象(初级篇)》文章介绍了面向对象基本知识:面向对象是一种编程方式,此编程方式的实现是基于对类和对象的使用类是一个模板,模板中包装了多个“函数”供使用(可以讲多函数

    2022年7月5日
  • 永恒之蓝漏洞入侵_永恒之蓝漏洞探测

    永恒之蓝漏洞入侵_永恒之蓝漏洞探测一、基础知识介绍:1.何为永恒之蓝?永恒之蓝(EternalBlue)爆发于2017年4月14日晚,是一种利用Windows系统的SMB协议漏洞来获取系统的最高权限,以此来控制被入侵的计算机。甚至于2017年5月12日,不法分子通过改造“永恒之蓝”制作了wannacry勒索病毒,使全世界大范围内遭受了该勒索病毒,甚至波及到学校、大型企业、政府等机构,只能通过支付高额的赎…

    2022年10月17日
  • pycharm中使用anaconda部署python环境_anaconda pycharm环境配置

    pycharm中使用anaconda部署python环境_anaconda pycharm环境配置Pycharm使用anaconda环境(原环境base)注意本教程是针对使用anaconda的新手,添加的是anaconda自带的base环境!首先打开或者新建一个Python项目File->Settings->Project->PythonInterpreter,然后在右边PythonInterpreter看一下又没有anaconde的选项,如果有,就直接选中,然后就可以了,如果没有那就继续看下去.如果没有默认读取anaconda的选项,那

    2022年8月25日
  • android toast_Android Toast

    android toast_Android ToastandroidtoastToastmessageisusefultoshownotificationforsmalltimeinandroidapp.Inthistutorial,we’lldiscussandimplementandroidToastmessageexample.Toast消息对在Android应用中显示少量通知非常有用。在本教…

    2022年9月13日
  • Kafka基本原理详解(超详细!)

    Kafka基本原理详解(超详细!)目录一、概念理解(1)产生背景(2)Kafka的特性(3)Kafka场景应用(4)Kafka一些重要设计思想二、消息队列通信的模式(1)点对点模式(2)发布订阅模式三、Kafka的架构原理(1)基础架构与名词解释(2)工作流程分析(1)发送数据(2)保存数据(1)Partition结构(2)Message结构(3)存储策略(3)消费数据一、概念理解Kafka是最初由Linkedin公司开发,是一个分布式、支持分区的(partition)、多副本的(replica),基于zookeeper协调的分布式消

    2022年5月20日

发表回复

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

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