java - 如何抛出新的 ElementNotFoundException?

标签 java selenium selenium-webdriver

int btnSize = driver.findElements(By.xpath("...")).size();

if ( btnSize > 1) {
    List<WebElement> b = driver.findElements(By.xpath("..."));
} else if (btnSize == 1){
    WebElement b = driver.findElement(By.xpath("..."));
} else {

    //How do I throw an Exception (e.g. ElementNotFoundException)
    //these variants did not work?

    throw ElementNotFoundException;     
    throw (new ElementNotFoundException);
    throw (new ElementNotFoundException("not found"));
    throw (new ElementNotFoundException(Exception e));
}

最佳答案

当抛出一个新的异常时,基本上你通过调用它的构造函数来创建一个对象。所以它是
throw new ElementNotFoundException("not found");
throw new ElementNotFoundException(exception)
其中异常是异常你咳嗽的对象 ;)

关于java - 如何抛出新的 ElementNotFoundException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21703405/

相关文章:

java - 使用 Java 从字符串中提取标记

r - 尝试使用 RSelenium 检测并填充表单

javascript - Selenium Webdriver-python,无法找到动态元素,所有可能的方法都试过了

java - WebDriver.getWindowHandle() 方法

python - 将变量注入(inject)函数; Python

java - File.list() 是否有序(java)

java - 这种 vigenere 密码在 Java 中是否可行?

node.js - Node Selenium ChromeDriver Ubuntu NoSuchSessionError : This driver instance does not have a valid session ID

java - xpath:无法单击任何复选框

java - 更快的自动完成/即时搜索 Java 移动应用程序