In Java, best way to check if Selenium WebDriver has quit -


i need check collection of page objects see, each one, if quit() has been called on webdriver.

i've written following method check webdriver's state:

public static boolean hasquit(webdriver driver) {         try {             driver.gettitle();             return false;         } catch (sessionnotfoundexception e) {             return true;         } } 

i don't having throw , catch exception discover truth of boolean, seems have no choice since webdriver api doesn't provide method check if driver has quit.

so question is, is there better way check if webdriver has quit?

i found similar (and more general) question here, question did not have code had been tried, , answer set webdriver null after quiting (which don't have control over).

if quit() has been called, driver.tostring() returns null:

>>> firefoxdriver: firefox on xp (null)) 

otherwise, returns hashcode of object:

>>> firefoxdriver: firefox on xp (9f897f52-3a13-40d4-800b-7dec26a0c84d) 

so check null when assigning boolean:

boolean hasquit = driver.tostring().contains("(null)"); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -