Hello. Faced the problem of how to properly handle the thrown exception, I began to read examples, but this is exactly what I did not find anywhere in my case. Please help.
Call the method with the command:
parse.openPage("http://"+ipAddresses.get(i)+"/"); The openPage method itself:
void openPage(String sAddress){ driver.get(sAddress); **waitLoadById**(30,"button"); } Method waitLoadById:
void waitLoadById(int sec, String sId) { WebElement presenceElement = (new WebDriverWait(driver, sec)).until(ExpectedConditions.presenceOfElementLocated(By.id(sId))); } If the item does not show up after 20 seconds, ExpectedCondition will throw a TimeoutException exception. Where to catch him? I try the parse.openPage command ("http: //" + ipAddresses.get (i) + "/") in a try-catch:
try{ parse.openPage("http://"+ipAddresses.get(i)+"/"); //другие команды по дальнейшему парсингу }catch(TimeoutException te){ прекратить парсинг этого ip-адреса и начать заново с новым ip } It turns out that the catch block is triggered even when the element is detected. That is, WevDriverWait itself throws some kind of exception, which, respectively, is also caught by my catch?
The goal is this: if the item is found, continue parsing; if the item is not found, stop parsing the address and go to the next one. I'm a little confused where to place try-cath blocks, what to catch, etc.?
te.printStackTrace()in the block and see where the exception occurs in the code - m. vokhm