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

时间:2015-10-06 11:05:18

标签: java selenium phantomjs headless-browser htmlunit-driver

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

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

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());

请在此处找到运行HTMLUnitDriver的selenium代码:

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

在此之后,没有任何反应。

有人可以帮帮我吗?提前谢谢!

0 个答案:

没有答案