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

  • what error it throws if you close it inside exception – PDHide Sep 16 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 Sep 16 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 Sep 16 at 9: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

| improve this answer | |
  • I trid all but no luck. Original exception is happening because of element not available to click. – ChathuD Sep 16 at 13:37
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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