Java 无头浏览器自动化-Phantomjs&;Selenium Webdriver jar中的HtmlUnitDriver

Java 无头浏览器自动化-Phantomjs&;Selenium Webdriver jar中的HtmlUnitDriver,java,selenium,phantomjs,headless-browser,htmlunit-driver,Java,Selenium,Phantomjs,Headless Browser,Htmlunit Driver,我正在尝试实现无头浏览器自动化。我尝试了Phantomjs和HtmlUnitDriver,但没有成功地使用它们 我在我的办公室代理网络。我不确定这是否是问题所在。 请在下面找到我使用Phantomjs的selenium代码: DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true); caps.setCapability(PhantomJSDriverService.PHANTOM

我正在尝试实现无头浏览器自动化。我尝试了
Phantomjs
HtmlUnitDriver
,但没有成功地使用它们

我在我的办公室代理网络。我不确定这是否是问题所在。 请在下面找到我使用Phantomjs的selenium代码:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); 
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/XXXX/Downloads/phantomjs-2.0.0-windows/phantomjs-2.0.0-windows/bin/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("www.google.com"+ "/");
System.out.println(driver.getTitle());
请在此处找到要运行的selenium代码
HTMLUnitDriver

HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.setJavascriptEnabled(true);
driver.get("http://www.google.com");
System.out.println("Title of the page "+ driver.getTitle());
这里的两种编码都不起作用。打开的驱动程序页面的标题永远不会显示。我也没有收到任何错误

当我尝试Phantomjs时,控制台上会显示以下消息:

Oct 06, 2015 4:40:36 PM org.openqa.selenium.phantomjs.PhantomJSDriverService      <init>
INFO: executable: C:\Users\321106\Downloads\phantomjs-2.0.0-   windows\phantomjs-2.0.0-windows\bin\phantomjs.exe
Oct 06, 2015 4:40:36 PM org.openqa.selenium.phantomjs.PhantomJSDriverService   <init>
INFO: port: 14480
Oct 06, 2015 4:40:36 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=14480, --webdriver- logfile=D:\JMeter\JMeterSample\phantomjsdriver.log]
Oct 06, 2015 4:40:36 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO  - 2015-10-06T11:10:42.008Z] GhostDriver - Main - running on port  14480
[INFO  - 2015-10-06T11:10:43.890Z] Session [e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd] - page.settings -   {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenW indows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessE nabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/538.1  (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2015-10-06T11:10:43.890Z] Session [e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd] - page.customHeaders:  - {}
[INFO  - 2015-10-06T11:10:43.890Z] Session [e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd] - Session.negotiatedCapabilities -  {"browserName":"phantomjs","version":"2.0.0","driverName":"ghostdriver","driverV ersion":"1.2.0","platform":"windows-7- 32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2015-10-06T11:10:43.891Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd
2015年10月6日下午4:40:36 org.openqa.selenium.phantomjs.PhantomJSDriverService
信息:可执行文件:C:\Users\321106\Downloads\phantomjs-2.0.0-windows\phantomjs-2.0.0-windows\bin\phantomjs.exe
2015年10月6日下午4:40:36 org.openqa.selenium.phantomjs.PhantomJSDriverService
信息:端口:14480
2015年10月6日下午4:40:36 org.openqa.selenium.phantomjs.PhantomJSDriverService
信息:参数:[--webdriver=14480,--webdriver-logfile=D:\JMeter\JMeterSample\phantomjsdriver.log]
2015年10月6日下午4:40:36 org.openqa.selenium.phantomjs.PhantomJSDriverService
信息:环境:{}
[信息-2015-10-06T11:10:42.008Z]幽灵驱动程序-主-在端口14480上运行
会话[e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd]-page.settings-{“xsauditingEnabled”:false,“javascriptCanCloseWindows”:true,“javascriptCanOpenW indows”:true,“javascriptEnabled”:true,“loadImages”:true,“localToRemoteUrlAccessE-nabled”:false,“userAgent”:“Mozilla/5.0(Windows NT 6.1)AppleWebKit/538.1(KHTML,像Gecko)PhantomJS/2.0.0safari/538.1,“webSecurityEnabled”:true}
[INFO-2015-10-06T11:10:43.890Z]会话[e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd]-第页。自定义标题:-{}
[INFO-2015-10-06T11:10:43.890Z]会话[e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd]-会话协商能力-{“浏览器名”:“幻影”,“版本”:“2.0.0”,“驱动程序名”:“幻影驱动程序”,“驱动程序版本”:“1.2.0”,“平台”:“windows-7-32位”,“javascriptEnabled”:true,“takesScreenshot”:true,“handlesAlerts”:false,“databaseEnabled”:false,“locationContextEnabled”:false,“applicationCacheEnabled”:false,“browserConnectionEnabled”:false,“CSSSelectorEnabled”:true,“WebStorage Enabled”:false,“rotatable”:false,“acceptSslCerts”:false,“nativeEvents”:true,“proxy”:“direct”}
[INFO-2015-10-06T11:10:43.891Z]会话管理器RQHAND-"发布新闻会话命令-创建新会话:e30bd0a0-6c1a-11e5-abc9-4de82f9ca0dd
在这之后,什么也没有发生


有人能帮我吗?提前谢谢!

对于HtmlUnitDriver,你可以使用
.setHTTPProxy()
,还可以确保你使用的是最新版本。@AhmedAshour:嗨..你能告诉我如何为Phantomjs设置代理吗?我试过了,但它不起作用…caps.setCapability(CapabilityType.PROXY,new PROXY().setHttpProxy(myProxy));caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_属性,“C:/XXX/Downloads/PHANTOMJS-2.0.0-windows/PHANTOMJS-2.0.0-windows/bin/PHANTOMJS.exe”);对不起,我不熟悉Phantomjs。没有人尝试过使用Java将Selenium与Phantomjs集成吗?有人能帮我吗?