1) { List b = driver.f-6ren">
gpt4 book ai didi

java - 如何抛出新的 ElementNotFoundException?

转载 作者:行者123 更新时间:2023-11-29 05:29:13 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com