0

As on my code I'm trying to find an element and click on it. If the element is not available then there will be an exception. So inside the exception I'm trying to close the web driver. But as on the image when I say driver.Quit(); it's not quitting as the driver is in an exception. So is there any other way to close the driver and start it again when something like this happens.

I tried with killing the process names contain "web driver","chrome driver" text. But that didt work well too.

 try
                    {
                        driver.Navigate().GoToUrl("https://www.appreviewguru.com/");

                        Thread.Sleep(9000);

                        driver.FindElement(By.Id("mainnbt")).Click();

                        Thread.Sleep(9000);
                        DateTime now2 = DateTime.Now;
                        File.AppendAllText(@"C:\driver\aaa.txt", proxies[i] + now2.ToString() + Environment.NewLine);
                        driver.Close();
                    }
                    catch (Exception e)
                    {
                        // driver.Close();
                        driver.Quit();
                    }

enter image description here

3
  • what error it throws if you close it inside exception
    – PDHide
    Commented Sep 16, 2020 at 6:30
  • Actually I'm not getting any error or exception. What it does was wait few seconds on the driver.close(); line. Without doing nothing it will go to the next line.You can see the chrome driver and the Chrome browsers are at the task bar.
    – ChathuD
    Commented Sep 16, 2020 at 6:44
  • Check your call stack, in the screen shot it appears like something download videos.dll which might be creating another instance of browser
    – Sunil K
    Commented Sep 16, 2020 at 9:38

2 Answers 2

1

If the [SetUp] runs without exception the [TearDown] should to. So, this usually only happens when I 'Debug' my tests. When it does I can kill the orphaned drivers with this cmd, kill -processname chromedriver -ErrorAction SilentlyContinue or just hit 'Continue' in the debugger to let things play out naturally.

1
  • Yes, here's what I think is happening. The use of the Devtools protocol leaves that port open when exception occurs. (It should close it, but...). Just closing the browser window and the console window for that session is not enough! So killing the process will also kill the open socket. Commented Mar 1, 2021 at 16:38
0

Please check removing sleep threads. And try running wether after any exception the driver closes the browser. Probably problem is with sleep threads where in between its control stuck or may control is not getting return to driver. Also add console.log('') between the each line statment will help in debugging or f11

1
  • I trid all but no luck. Original exception is happening because of element not available to click.
    – ChathuD
    Commented Sep 16, 2020 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.