jBrowserDriver 一个可编程、可嵌入的Web浏览器驱动程序,与Selenium WebDriver兼容,且无头WebKIT纯Java

官方地址:https://github.com/MachinePublishers/jBrowserDriver   

jBrowserDriver 的每个实例都由一个单独的Java进程支持


一、支持Maven安装构建:

<dependency>
  <groupId>com.machinepublishers</groupId>
  <artifactId>jbrowserdriver</artifactId>
  <version>1.1.1</version>
</dependency>
二、最新Jar包下载:

大小及占用空间如下,如果下载的不是,则下载有误,请重新下载:

JBrowserDriver jars.rar      

三、基础测试代码:

package com.test.jbrowserdriver;
import com.machinepublishers.jbrowserdriver.JBrowserDriver;
import com.machinepublishers.jbrowserdriver.Settings;
import com.machinepublishers.jbrowserdriver.Timezone;

public class TestJBrowserDriver {
	public static void main(String[] args) {
		JBrowserDriver driver = new JBrowserDriver(Settings.builder().timezone(Timezone.AMERICA_NEWYORK).build());
		try {
			driver.get("https://www.taobao.com");
			System.out.println(driver.getStatusCode());
			System.out.println(driver.getPageSource());
		} catch (Exception e) {
			e.printStackTrace();
		}
		driver.quit();
	}
}
打开淘宝网页,并且输出网页源代码。

四、如果从远程Selenium服务器运行,最少需要如下Jar包,测试代码如下:

JBrowserDriver jars(remote).rar      


package com.test.jbrowserdriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import com.machinepublishers.jbrowserdriver.Settings;
import com.machinepublishers.jbrowserdriver.Timezone;

public class Example {
	public static void main(String[] args) throws MalformedURLException {

		DesiredCapabilities capabilities = new DesiredCapabilities("jbrowserdriver", "1", Platform.ANY);

		// Optionally customize the settings
		capabilities.merge(Settings.builder().timezone(Timezone.AMERICA_NEWYORK).buildCapabilities());

		RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

		driver.get("https://www.taobao.com");

		System.out.println(driver.getPageSource());

		driver.quit();
	}
}