I am trying to use the PhantomJSDriver
. The code below works with
FirefoxDriver
but will not work with PhantomJSDriver. The error is:
[ERROR - 2016-02-12T16:02:47.717Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1455292967683 org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'email''
Is there any clear guides on how to do this in Java, or can anyone get this working to login? I'm struggling to find some clarity on this topic.
I'm assuming the error is something to do with the browser being headless which therefore messes up with the paths but I have seen others using similar code and it works for them.
WebDriver driver = new PhantomJSDriver();
try {
System.out.println("Logging in to Facebook...");
driver.get("https://www.facebook.com/login");
System.out.println(driver.getTitle());
driver.findElement(By.id("email")).sendKeys("USERNAME");
driver.findElement(By.id("pass")).sendKeys("PASS");
driver.findElement(By.id("loginbutton")).click();
}
catch (Exception e) {
e.printStackTrace();
}