小代码改进

小代码改进

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


相关推荐

  • laravel实现批量添加数据

    laravel实现批量添加数据

    2021年11月8日
    47
  • HDU-3363 Count the string KMP 巧用next函数

    HDU-3363 Count the string KMP 巧用next函数

    2021年8月12日
    41
  • jar中没有主清单属性啥意思啊_java没有主清单属性

    jar中没有主清单属性啥意思啊_java没有主清单属性在pom文件中,添加如下即可&lt;plugin&gt;&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;…

    2025年9月15日
    5
  • 协方差矩阵的计算及意义「建议收藏」

    协方差矩阵的计算及意义「建议收藏」声明:博文转自https://blog.csdn.net/mr_hhh/article/details/78490576一、首先看一个比较简洁明了的协方差计算介绍:1.协方差定义X、Y是两个随机变量,X、Y的协方差cov(X,Y)定义为:其中,2.协方差矩阵定义矩阵中的数据按行排列与按列排列求出的协方差矩阵是不同的,这里默认数据是按行排列。即每一行是一个obs…

    2022年6月28日
    28
  • linux查看udp端口占用命令,详解Linux查看端口占用「建议收藏」

    linux查看udp端口占用命令,详解Linux查看端口占用「建议收藏」在使用计算机的过程中,有时会碰到端口被占用的情况,这时候需要查看端口占用情况进行问题排查。在linux系统中,端口占用的情况也时有发生,一般情况下可以使用lsof和netstat两个命令来查看端口占用情况。下面我们就分别介绍Linux查看端口占用用到的lsof和netstat命令:1、lsof命令lsof(listopenfiles)命令功能:列出当前系统打开文件。在linux系统中,一切皆文…

    2022年7月27日
    5
  • scrollHeight,clientHeight,scrollTop

    scrollHeight,clientHeight,scrollTop移动端加载数据时,由于数据太多,不会一次性全部加载出来。有些会采用pc端那样用分页码的形式,但是更多的确实滑动滚动条到内容最后,加载更多内容出来。一般引入了三方的前端框架和插件,基本都会有此功能。偶尔会需要采用原生js实现,故而此处就介绍下原生js的实现方式。另外附上jquery的实现方式。原生js实现思路需要三个高度:scrollHeight(文档内容实际高度,包括超出视窗的溢出部分)、scrollTop(滚动条滚动距离)、clientHeight(窗口可视范围高度)。当clientHeig

    2022年7月23日
    11

发表回复

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

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