Sanjay Karkera
Sanjay Karkera

Reputation: 131

driver.close() method is not working in Selenium WebDriver on Firefox

I am writing a simple program in Eclipse using JUnit annotation.

diver.close() is not closing my Firefox browser after the tests. It works fine with Chrome. Code snippet is here.

public class FireFox1 {
    WebDriver driver;

    @Before
    public void setUp() {
        driver= new FirefoxDriver();
        driver.get("http://book.theautomatedtester.co.uk/chapter4");
    }

    @After
    public void tearDown() {
        driver.close();
    }

    @Test
    public void testExamples() {
        WebElement element= driver.findElement(By.id("nextBid"));
        element.sendKeys("100");     

    }
} 

Upvotes: 13

Views: 25380

Answers (5)

Nithin N
Nithin N

Reputation: 1

This is what the problem in Firefox driver.close() works in Firefox only with internet connection but in case of Chrome it works without internet connection.

Upvotes: 0

E.E
E.E

Reputation: 9

Use latest GeckoDriver.exe (17) with Latest FireFox (54.0); It works fine for me. I had the same problem before.

This problem that you are facing is completely a compatibility problem between driver & Browser version.

driver.close(); should have work without problem if you use above versions. Let me know if it works.

Upvotes: 0

sras
sras

Reputation: 838

Better use driver.quit() method. It closes the browser, but due to some unknown issues it throws NullPointerException. Just catch it..

try{
    driver.quit();
   }catch (Exception e){
      System.out.println("Nothing to do with it");
      }

Upvotes: 3

Mukesh Guduru
Mukesh Guduru

Reputation: 51

sometimes while on repeated usages,we'll facing problems with driver.close(). Anyways driver.quit() will rectify your problem.

Generally driver.close() closes the browser(the instance of driver is still intact) and driver.quit() is to kill the webdriver instance. As anyhow you are using here for only one page,then you can go with driver.quit().

Thank you.

Upvotes: 5

dinesh
dinesh

Reputation: 48

Assuming you have started 5 browsers(classes) parallely using grid:

driver.close - Used for close the current browser( where execution going on)

driver.quit - Used for close all the browsers started by the current execution.

You can use any one of this..

May be browser compatiblity issue, try to downgrade the FF let we see...

Upvotes: 1

Related Questions