I work on Selenium and PhantomJS with GhostDriver in Java. I make some tests which work correctly, but since the last week, some sudden errors prevent to work, without modify the code...
- Windows 7.
- JDK is in 1.7.0_75 version.
- PhantomJS 1.9.7 is include with it path.
- GhostDriver 1.1.0 is include in an Eclipse Java SE Project.
- Selenium 2.43.1 is include in an Eclipse Java SE Project.
This is an example of the basic code I use, and worked before the last week :
//The imports
import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
//The code
Selenium selenium;
String baseUrl = "http://www.url.com";
WebDriver driver;
DesiredCapabilities dCaps;
String phantom = "phantomjs-1.9.7-windows/phantomjs.exe";
dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", true);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--ignore-ssl-errors=true"});
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantom);
driver = new PhantomJSDriver(dCaps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.open(url);
selenium.type("name=element", "example");
selenium.click("name=Send");
selenium.waitForPageToLoad("30000");
driver.quit();
selenium.stop();
I can use Selenium alone, and it works... (with and without proxy) I can use PhantomJS alone, and it works...
But when I use the two with GhostDriver (so, only since the last week) I have two problems :
- The log show me : [ERROR - 2015-05-05T14:27:09.344Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1430836029300
- I catch error : Element name=element not found
I understand that elements are not presents or wrong (I control every time that's are not wrong)... May be the page is not correctly loaded... I can't use screen captures for see the problem : I have black screens only...
I'm actually adding code about waiting and controlling if an element is present which different ways... But nothing change for the moment :
- selenium.waitForPageToLoad(30000);
- Thread.sleep(7000);
- selenium.isElementPresent(myElement);
I begin to try driver.findElement() with selector and selenium.waitForFrameToLoad()...
I tried to remove PhantomJS and replace by FirefoxDriver, it works... I tried to comment or not parts of dCaps or driver... Nothing works...
I know that PhantomJS/GhostDriver seems to be the problem... But I don't understand !
Is there a problem of selector? Is there a specific way to use wait and control code? May be I made an error? Have I forget something important? Why the problem appear only now, without changes?