How to run ghostdriver with Selenium using java

纵然是瞬间 提交于 2019-11-27 14:26:37

I believe this link will answer your questions. You will need Selenium 2.28.0, and PhantomJS 1.8. I have tested this, and it works as advertised, although my tests were precursory. Note that you need to download the Selenium zip file to get the jar which contains the bindings. The Maven repo does not yet include it.

http://ivandemarino.me/2012/12/04/Finally-GhostDriver-1-0-0/

Just to clarify for others who might see this, to run it from java:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                "/Path/to/bin/phantomjs");                  
driver = new PhantomJSDriver(caps);

Then it can be used like a usual WebDriver.

First download the exe file of the PhantomJSDriver. Don't need to install, only download this file from http://phantomjs.org/download.html and simply give the path of the exe file in the given code.

 public class Browserlaunch {
    public static void main(String[] args) {
        DesiredCapabilities DesireCaps = new DesiredCapabilities();
        DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/Drivers/phantomjs/bin/phantomjs.exe");
        WebDriver driver=new PhantomJSDriver(DesireCaps);
        driver.get("http://google.com");

   }
}

Only set system property:

System.setProperty("phantomjs.binary.path", "lib/phantomjs.exe");
WebDriver driver = new PhantomJSDriver();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!