Reputation: 190
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());
}
}
Upvotes: 1
Views: 775
Reputation: 2805
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);
...
Upvotes: 1