小代码改进

小代码改进

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


相关推荐

  • C语言的seekg函数,C++ seekg函数用法详解[通俗易懂]

    C语言的seekg函数,C++ seekg函数用法详解[通俗易懂]很多时候用户可能会这样操作,打开一个文件,处理其中的所有数据,然后将文件倒回到开头,再次对它进行处理,但是这可能有点不同。例如,用户可能会要求程序在数据库中搜索某种类型的所有记录,当这些记录被找到时,用户又可能希望在数据库中搜索其他类型的所有记录。文件流类提供了许多不同的成员函数,可以用来在文件中移动。其中的一个方法如下:seekg(offset,place);这个输入流类的成员函数的名字se…

    2022年4月29日
    180
  • 概率矩阵分解模型 PMF[通俗易懂]

    概率矩阵分解模型 PMF[通俗易懂]本文是论文《一种结合推荐对象间关联关系的社会化推荐算法》的笔记(上)。因为对其中的概率矩阵分解(ProbabilisticMatrixFactorization,PMF)不够了解,因而我先去脑补了PMF在推荐系统中的应用,然后再对论文进行总结。主要内容包括svd的两种形式和PMF的介绍。

    2022年6月18日
    62
  • 阿里面试官问我,你们的需求研发/开发流程是怎样的?我???

    阿里面试官问我,你们的需求研发/开发流程是怎样的?我???这可能是全网第一篇揭秘阿里,腾讯,字节这样的大厂研发流程的文章。

    2022年6月16日
    37
  • 报错415怎么解决_服务器请求415

    报错415怎么解决_服务器请求415415错误

    2025年6月19日
    3
  • 搜索引擎looka_Alook浏览器使用方法教程[通俗易懂]

    Alook极简且强大,致力成为iOS最佳浏览器。具有着与iCloud同步、内置14种语言翻译、自定义搜索引擎等多种功能,很多新用户还不知道如何使用这款APP,下面小编就和大家分享下Alook浏览器的使用教程。Alook浏览器使用方法:1、下载并打开ALOOK浏览器,会出现引导菜单该浏览器是没有广告的,要是没有会员看视频比在APP看还要给力。2、看视频的时候卡其开启视频悬窗功能,还有全屏模式和无图模…

    2022年4月7日
    264
  • pycharm搭配anaconda_在anaconda中安装pycharm

    pycharm搭配anaconda_在anaconda中安装pycharm为了以后自己忘记可以不用再去找方法,在此记下步骤一、为已存在的project设置环境File–Settings–Pythoninterpreter找到自己Anaconda下的python.exe这里勾选makeavailabletoallprojects在这里就可以看到这个环境里有什么包了,可以看到高亮部分有pandas二、newproject在这里要选择previouslyconfiguredinterpreter点击右边的…进行设置在Cond

    2022年8月29日
    4

发表回复

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

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