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.?

  • one
    So put a catch te.printStackTrace() in the block and see where the exception occurs in the code - m. vokhm
  • and attach to the issue trace - Senior Pomidor
  • Thanks, trace helped. - Cenzor
  • @Cenzor write the answer so that in the future people will know the solution - Senior Pomidor
  • With the help of a look, whoever throws an exception looks at which stack it passes. Earlier, in each method I explicitly threw an exception down the stack, this time I began to catch it with the method that is at the bottom of the exception call chain. All logic is processed as needed. - Cenzor

0