Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Se (1)-Open and close browsers

Shulou Source: shulou.com Published: 2022-06-03 06:49:31 10月14日 Update

package test;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class OpenCloseBrowser {

@Test

public void test() throws InterruptedException{

//Firefox

/*System.setProperty("webdriver.firefox.bin", "D:/Firefox/firefox.exe");

WebDriver wd = new FirefoxDriver();*/

//chrome

System.setProperty("webdriver.chrome.driver", "D:/01 Learn WebDriver/chromedriver.exe");

WebDriver wd = new ChromeDriver();

Thread.sleep(5000);

//ie

/*System.setProperty("webdriver.ie.driver", "D:/01 Learn WebDriver/IEDriverServer.exe");

WebDriver wd = new InternetExplorerDriver();*/

//wd.close();

wd.quit();

}

}

The close method closes the browser window;

The quit method is to quit the entire webdriver;

In other words, after close, wd can still perform other operations;

It is recommended to use the quit method, which is more complete and safer.

Tags: Methods browsers browsing security that is suggestions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux Xiaomi MariaDB OPPO Reno