0

I'm trying to do headless browser automation. I have tried both Phantomjs and HtmlUnitDriver but I have not been successful using them.

I'm in my office proxy network. I'm not sure if that's the issue. Please find my selenium code to use Phantomjs below:

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

Please find the selenium code to run HTMLUnitDriver here:

HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.setJavascriptEnabled(true);
driver.get("http://www.google.com");
System.out.println("Title of the page "+ driver.getTitle());

Both of the coding here doesn't work. The title of the opened driver page is never displayed. I don't get any errors also.

I get the following message on the console when I try 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

After this, nothing happens.

Can someone please help me? Thanks in advance!

Mosam Mehta
  • 1,658
  • 6
  • 25
  • 34
user1395264
  • 143
  • 3
  • 18
  • For HtmlUnitDriver, you can use `.setHTTPProxy()`, also ensure you are using the latest version. – Ahmed Ashour Oct 06 '15 at 11:38
  • @AhmedAshour: hi .. can you please tell me how to set proxy for Phantomjs? I tried this and it doesn't work ... _caps.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(myProxy)); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/XXX/Downloads/phantomjs-2.0.0-windows/phantomjs-2.0.0-windows/bin/phantomjs.exe");_ – user1395264 Oct 06 '15 at 13:02
  • Sorry, I am not familiar with Phantomjs – Ahmed Ashour Oct 06 '15 at 13:06
  • has no one tried integrating Selenium with Phantomjs using Java? can someone help me please? – user1395264 Oct 07 '15 at 11:19

0 Answers0