简体   繁体   中英

How to connect phantomjs to selenium using java

I have a problem with my code - see below. Could somebody tell me what is wrong? It won't connect but everything is correct.

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.testng.annotations.Test;

public class Main {
    @Test
    public static void main(String[] args){
        File src = new File("phan//bin//phantomjs");
//      System.out.println("test:" + File);
        System.setProperty("phantomjs.binary.path",src.getAbsolutePath());
        WebDriver driver =  new PhantomJSDriver();
        driver.get("http://facebook.com");
        System.out.println(driver.getTitle());
    }
}

Try following:

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;

...

File phantomJSBinary = new File("path" + File.separator + "to" + File.separator + "phantomjs");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJSBinary.getAbsolutePath());
WebDriver driver = new PhantomJSDriver(caps);

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM