driver.close()方法在Firefox上的Selenium WebDriver中不起作用

driver.close()方法在Firefox上的Selenium WebDriver中不起作用

问题描述:

我正在使用JUnit注释在Eclipse中编写一个简单程序.

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

diver.close()没有关闭我的Firefox浏览器. Chrome可以正常使用.代码段在这里.

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");     

    }
} 

有时,在重复使用时,我们会遇到driver.close()的问题. 无论如何,driver.quit()将纠正您的问题.

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

通常driver.close()关闭浏览器(驱动程序实例仍然完好无损),而driver.quit()则杀死webdriver实例.无论如何,您只在这里使用一页,然后就可以使用driver.quit().

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().

谢谢.