小代码改进

小代码改进

 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)
上一篇 2021年8月29日 下午9:00
下一篇 2021年8月29日 下午10:00


相关推荐

  • idea gitignore不起作用

    idea gitignore不起作用有时候 gitignore 会对部分文件 文件夹失效 大概原因是由于新创建的文件已经出现在 git 本地仓库的缓存 所以 gitignore 就失效了解决办法就是清空一下 git 仓库的缓存 重新提交一次就好了 gitrm rcached gitadd gitcommit m update gitignore

    2026年3月26日
    3
  • isnotempty和isnotnull_likely与possible和probable的区别

    isnotempty和isnotnull_likely与possible和probable的区别前两天因为用到isBlank,上网查了下,顺便放在CSDN上,希望能帮助到更多的人!!!isNotEmpty将空格也作为参数,isNotBlank则排除空格参数参考StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException…

    2022年8月12日
    11
  • 闫学灿acwing_acm题

    闫学灿acwing_acm题在给定的 N 个整数 A1,A2……AN 中选出两个进行 xor(异或)运算,得到的结果最大是多少?输入格式第一行输入一个整数 N。第二行输入 N 个整数 A1~AN。输出格式输出一个整数表示答案。数据范围1≤N≤105,0≤Ai<231输入样例:31 2 3输出样例:3#include<bits/stdc++.h>using namespace std;const int N = 31e5 + 10;int trie[N][2],ctx,cnt[N];

    2022年8月9日
    6
  • 笛卡尔积 php,PHP笛卡尔积实现算法示例

    笛卡尔积 php,PHP笛卡尔积实现算法示例本文实例讲述了PHP笛卡尔积实现算法。分享给大家供大家参考,具体如下:$arr=array(array(1,3,4,5),array(3,5,7,9),array(76,6,1,0));/****实现二维数组的笛卡尔积组合**$arr要进行笛卡尔积的二维数组**$str最终实现的笛卡尔积组合,可不写**@returnarray**/functioncartesian($arr,…

    2022年7月11日
    19
  • mysql通配符和正则表达式

    mysql通配符和正则表达式通配符关键字是like。表示要跟like后的字符串完全匹配才能匹配上。如果没有通配符,匹配字符串时,like就跟等于号是相同含义的。like和等于的区别就是like后字符串里面可以插入一些通配符,类似于可变字符,使得字符串匹配难度降低一点。通配符有下面两个。%(百分号)匹配任意多个字符(0个或多个)_(下划线)匹配一个字符(有且仅有一个)正则表达式关键字是regexp(regularexpression简写)。正则匹配不用完全匹配,只需包含…

    2022年6月20日
    25
  • frameset应用

    frameset应用1 标签解析 lt frameset gt lt frameset gt frameset 元素定义一个框架集 它被用来组织多个窗口 框架 组织好在页面显示 lt frame gt lt frame gt frame 标签定义 frameset 中的一个特定的窗口 框架 嵌套在 frameset 标签中使用 lt noframe gt lt noframe gt 在 frame

    2026年3月19日
    2

发表回复

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

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