0

I have an issue where sometimes driver.quit is being called on a non-existent browser. I'm working on figuring out why but in the meantime I have written the following (I am looking to do the Javascript version of this: https://stackoverflow.com/a/53909741/4427375):

console.log("I'm here");
try {driver.quit();} catch {
  console.log("Catch me");
}

I set a breakpoint on I'm here and the code will reach that point - if I run the driver quit it will fail with NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used. What I don't understand is why the catch block never runs.

Grant Curell
  • 1,321
  • 2
  • 16
  • 32

1 Answers1

0

It is because driver is running in a separate thread so the error is being thrown out of the context of what is above. driver.quit() returns a promise so if you want to handle the error you have to handle it like this:

driver.quit().catch((error) => {
// do stuff
});
Grant Curell
  • 1,321
  • 2
  • 16
  • 32