Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill chromedriver process in Selenium / Java

Tags:

I am currently running multiple Java programs through Jenkins using "Build Periodically" option and uses H 06 * * 1-5 (run it every day between 6 AM and 7 AM from Monday to Friday).

There are certain programs in which i click on Links which opens up a new window. Hence, I use the below Code

driver.findElement(By.xpath(".//*[@id='terms']/li[1]/a")).click();
System.out.println("Home Page is loaded Successfully and Terms of Use Link is clicked");
ArrayList<String> window1 = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(window1.get(1));
Thread.sleep(3000);
driver.close();
Thread.sleep(3000);
driver.switchTo().window(window1.get(0));

Now after the program runs, My other program following this fails because of the ChromeDriver.exe process that is already running.

I tried using driver.quit() instead of driver.close() in the code above, but it will close my entire browser.

Note: I have used driver.quit() at the end of my program which doesn't help me getting rid of the running Chromedriver.exe instance opened when i switched window.

Please suggest me a a good way to handle this issue. I have been looking for this solution in JAVA. But mostly i see answers for C#.

Thanks

like image 780
johnsonambrose Avatar asked Aug 14 '17 15:08

johnsonambrose


1 Answers

Don't use driver.close() on the particular page, let it be and use the code below in driver factory:

//This closes the browser after each test class 

@AfterClass
public void tearDown()
{
    driver.quit();
}

It should help.

like image 117
Sajal Singh Avatar answered Oct 11 '22 12:10

Sajal Singh