How to implement phantomjs using java
Download library for windows from the official site http://phantomjs.org/download.htmlPhantomjs maven repo https://mvnrepository.com/artifact/com.codeborne/phantomjsdriver
Extract phantomjs.exe to the current working directory
public static Capabilities getCapabilities() {
DesiredCapabilities cap = new DesiredCapabilities();
String proxy = "--proxy=ip:port;"; //if you need proxy
String auth = "--proxy-auth=login:pass"; //if you need proxy
String type = "--proxy-type=http"; //if you need proxy
String[] phantomArgs = new String[]{
"--webdriver-loglevel=NONE",
proxy, auth, type
};
String fileName = "phantomjs.exe";
cap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
cap.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, fileName);
cap.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userAgent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0");
return cap;
}
PhantomJSDriver driver = new PhantomJSDriver(getCapabilities());
Комментариев нет:
Отправить комментарий