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/