小代码改进

小代码改进

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


相关推荐

  • idea社区版_idea社区版够用吗

    idea社区版_idea社区版够用吗IDEA官网地址:https://www.jetbrains.com/idea/download/#section=windows下载社区版后,点击安装,就进行傻瓜式的安装了。以上两个步骤中有一个点击next的时候时间会稍稍有点久,耐心等待一下就好了。点击安装,IDEA社区版就安装完成了,安装好之后打开IDEA工具,会有如下提示:我是第一次使用,直接选择Donotimportsettings就行了。到这里就进入IDEA工具了,选择你喜欢的主题风格,当然这还不算正式的完成,我

    2022年9月2日
    5
  • 工商银行近20年实时大数据平台建设历程「建议收藏」

    工商银行近20年实时大数据平台建设历程「建议收藏」全文共4000个字,建议阅读10分钟一、工行实时大数据平台建设历程工商银行从2002年开始建设数据集市,当时主要使用Oracle类单机版的关系型数据库。随着数据量不断增加,开始引入TD、ED等国外高端一体机。2014年工行正式基于Hadoop技术建设了大数据平台,在其之上构建了企业级数据湖及数据仓库。2017年,随着AI技术的兴起,又开始建设机器学…

    2022年6月7日
    43
  • java json转map fastjson_java字符串转map

    java json转map fastjson_java字符串转mapjavajson传map,map数组

    2025年10月8日
    4
  • maven打包时打包指定的lib文件夹

    maven打包时打包指定的lib文件夹今天在打包自己的springboot项目时遇到了问题,报找不到类和符号。因为我有些依赖是放在项目lib文件夹中,那么打包的时候要连把它一起打包。修改pom.xml,添加一下内容:<build><plugins><plugin><groupId>or…

    2022年5月29日
    39
  • pycharm3.2激活码【在线注册码/序列号/破解码】

    pycharm3.2激活码【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    150
  • 芯片架构–四大处理器架构「建议收藏」

    芯片架构–四大处理器架构「建议收藏」处理器分为复杂指令集计算机(CISC)和精简指令集计算机(RISC)。1、x86架构我们使用的电脑以及公司的服务器,大部分采用了x86架构的处理器,以intel和AMD的处理器为主。x86架构的处理器采用了CISC指令集(复杂指令集计算机),x86架构的CPU分为x86和x86-64两类,目前主流的是x86-64,即64位的处理器。2、ARM架构我们的手机几乎全部使用了ARM架构,采用了RISC指令集(精简指令集),ARM的优势在于低功耗,因此非常适合手机等终端使用,x86架构的处理器无

    2025年9月28日
    2

发表回复

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

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