public boolean ElementExist(WebDriver driver,By locator)
    {
        try {
            driver.findElement(locator);
            return true;
        } catch (Exception e) {
            return false;
        }

    }

可以在类里面加上这个函数,然后调用这个函数

如果你不知道捕获的异常名字,可以直接用Exception代替,具体的话捕获元素不存在的异常NoSuchElementException

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-06-11
相关资源
相似解决方案