selenium - For cycle to catch an exception in Java -


i have code expected exception not being caught. i'm trying find element of time stale. loop 60 times attempting element before element not found exception. doesn't print out caught exception though still stale element exception.

public static webelement dropdown(webdriver driver) throws interruptedexception {     webelement element = null;     (int = 0; < 60; i++)     {         try         {             element = driver.findelement(by.cssselector("html body div.navbar.navbar-inverse.main-navbar "));             break;         }         catch (org.openqa.selenium.staleelementreferenceexception e)         {             system.out.println("caught staleelement exception");         }          thread.sleep(1000);     }      return element; } 

i think there more 1 issue here.

first, i'd give stacktrace. assume, exception thrown elsewhere , stacktrace tell where.

second, after have written "element" variable call break; statement, leave loop, therefore no exception thrown. can check yourself. assume for-loop exited while in first iteration.

therefore delete break; statement.

edit: if running unit test bet caught stalemateexception in actual method of program (not test). if exception caught there testmethod not receive it, caught. easy attempt see if that's case throw exception again after caught. instance:

catch (org.openqa.selenium.staleelementreferenceexception  e) {      throw e; } 

but don't throw exception main class! catch anywhere, exception can handled.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -