selenium工具

直接通过findElement方法获取某个元素,如果该元素不存在肯定会报错,selenium又没有可以判断该元素是否存在的方法

于是我们可以手写一个工具类,来判断这个元素是否存在

selenium的使用这里推荐一个学习网站 http://www.testclass.net/selenium_java/install-java

    /**
     * 判断某个元素是否存在
     */
    public boolean isJudgingElement(WebDriver webDriver, By by) {
        try {
            webDriver.findElement(by);
            return true;
        } catch (Exception e) {
            System.out.println("不存在此元素");
            return false;
        }
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-06-12
  • 2021-07-21
  • 2021-10-15
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案