* Looks into the Capabilities, the current $PATH and the System Properties for {@link
   * <p>NOTE: If the Capability, the $PATH and the System Property are set, the Capability takes
   * priority over the System Property, that in turn takes priority over the $PATH.
   * @param desiredCapabilities Capabilities in which we will look for the path to PhantomJS
   * @param docsLink The link to the PhantomJS documentation page
   * @param downloadLink The link to the PhantomJS download page
   * @return The driver executable as a {@link File} object
   * @throws IllegalStateException If the executable not found or cannot be executed
  protected static File findPhantomJS(
      Capabilities desiredCapabilities, String docsLink, String downloadLink) {
    String phantomjspath = null;
    if (desiredCapabilities != null
        && desiredCapabilities.getCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY) != null) {
      phantomjspath =
          (String) desiredCapabilities.getCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY);
    } else {
      phantomjspath = CommandLine.find(PHANTOMJS_DEFAULT_EXECUTABLE);
      phantomjspath = System.getProperty(PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjspath);

        phantomjspath != null,
        "The path to the driver executable must be set by the %s capability/system property/PATH variable;"
            + " for more information, see %s. "
            + "The latest version can be downloaded from %s",

    File phantomjs = new File(phantomjspath);
    return phantomjs;
  * Sets which PhantomJS executable the builder will use.
  * @param file The executable to use.
  * @return A self reference.
 public Builder usingPhantomJSExecutable(File file) {
     this.phantomjs = file;
     return this;