java退出登录关闭浏览器_Java+Selenium3方法篇20-浏览器退出quit和close的区别
本文介绍webdriver中关于浏览器退出操作。driver中有两个方法是关于浏览器关闭,一个叫quit,一个叫close。先来看看看两者的声明描述,请看下面声明文档。
/**
* Close the current window, quitting the browser if it's the last window currently open.
*/
void close();
/**
* Quits this driver, closing every associated window.
*/
void quit();从上面描述,可以知道,close方法是,关闭当前窗口,这个当前,如何理解,就是driver实例操作的页面,叫当前。如果当前窗口只有一个tab,那么这个close方法就相当于关闭了浏览器。quit方法就是直接退出并关闭所有关联的tab窗口。所以,close方法一般关闭一个tab,quit方法才是我们认为的完全关闭浏览器方法。为了证明这个,我们用一个例子去演示。
package lessons;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FindElement_LinkText {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.c
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
