如何使我使用Wait.Until的方法忽略在Selenium WebDriver中引发异常 [英] how to make a my method that is using Wait.Until ignore throwing exceptions in selenium webdriver

查看:709
本文介绍了如何使我使用Wait.Until的方法忽略在Selenium WebDriver中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法

private boolean findElements(
                                  String xpath,
                                  int timeOut ) {

        WebDriverWait wait = new WebDriverWait( driver, timeOut );

        try {
            if( wait.until( ExpectedConditions.visibilityOfElementLocated( By.xpath( xpath ) ) ) != null ) {
                return true;
            } else {
                return false;
            }
        } catch( NoSuchElementException e ) {
            e.printStackTrace();
            return false;
        }

    }

在找到元素时返回true,但在找不到元素时抛出异常,我如何使方法返回false而不是throwing异常,或者是否有更好的布尔方法或方法可以做到我的工作.

it returning true when element is found but it throwing an exception when element is not found, how can i make the method returning false instead of the exception throwing , or is there a better way or method that is boolean which can do the job for me.

亲切的问候

推荐答案

Jae Heon Lee回答了

Jae Heon Lee answered this question

  { 
    wait.until( ... ); return true;
  }
 catch(TimeoutException ex)
  { return false; } //might work if the wait.until( ... ) throws a TimeoutException

报告没有

这篇关于如何使我使用Wait.Until的方法忽略在Selenium WebDriver中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆