Background: I am using Selenium, C#, and Firefox to automate a task I perform regularly. I have choose this option because the website I am accessing no longer provides a REST API. In my code I regular check for errors such as failing to find a web element. At such time I want my application to gracefully exit with an error message.
For reference my current code
if (driver != null)
{
driver.Quit();
}
Problem: driver.Quit() does not close Firefox or the geckodriver when called from a webpage with a form that has been partially filled out. Instead a dialog will pop up which says
This page is asking you to confirm that you want to leave - data you have entered may not be saved.
Doing some searching I found the dialog is generated by the webpage. I tried looking for a Firefox preference to disable the popup but count not find one that was relevant. One search result turned information about killing the Firefox process.
Question: Is there a recommended Selenium approach for ensuring the Firefox and the web driver are terminated?