Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98814

How to close Selenium webdriver with a Winform button - C#

$
0
0

Hy,

I'm succesfully separeted my long run thread from the main application so I can reach the Winform UI.

Now I would like to put a button to the winform to close and quit the webdriver. Here are some snippets from the code:

private void buttonStart_Click(object sender, EventArgs e) 
{
 Task task = Task.Run((Action) ChromeApp);
}

public void chromeApp() 
{
 ChromeOptions options = new ChromeOptions();
 options.AddArguments("--disable-extensions");
 options.AddArguments("--disable-notifications");
 options.AddArguments("--disable-application-cache");
 options.AddArguments("--lang=en");

 IWebDriver driver = new ChromeDriver(options);
 driver.Navigate().GoToUrl("webpageurl");
 //
 //OTHER PARTS OF THE CODE
 //
 driver.Close();
 driver.Quit();
}

I've tried to close the driver with this code, but of course it didn't work:

The name 'driver' does not exist in the current context

public void buttonClose_Click(object sender, EventArgs e) 
{
 ChromeApp(driver).Close;
}

Can You help me in this case? Thank You!


Viewing all articles
Browse latest Browse all 98814

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>