selenium中启动chrome浏览器时加载插件

      使用selenium启动的chrome浏览器,一般是干净的浏览器,如果需要使用某个插件,那么启动浏览器时,就需要加载插件,

代码如下:

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

/*
 * chrome浏览器启动时加载某个插件
 */

public class KeywordBrowserChromePlug {

	public static void main(String[] args) {
		//存放插件的位置
		File plugPath = new File("D:\\google_fwzs\\fwzs.crx");
		
		//创建options对象
		ChromeOptions options = new ChromeOptions();
		
		//添加插件到chrome浏览器中
		options.addExtensions(plugPath);
		
		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
		
		//实例化driver时加载ChromeOptions
		WebDriver driver = new ChromeDriver(options);
		
		driver.get("http://www.baidu.com");
	}
}

 

你可能感兴趣的:(浏览器,java,seleinium)