phantomjs没有为可执行文件路径设置正确的DesiredCapabilities

时间:2018-06-11 12:34:39

标签: java maven selenium selenium-webdriver phantomjs

我正在尝试在webDriver的DesiredCapabilities对象中设置我的可执行文件phantomjs.exe的路径。但是,它会为指定的路径添加其他路径。我想它是从我的系统中取出来的,但是如何防止它这样做。代码如下:

  DesiredCapabilities DesireCaps = new DesiredCapabilities();
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"C:\Users\su.t\Desktop\phantomjs-2.1.1-linux-x86_64\bin\phantomjs");
        System.out.println(DesireCaps.getCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
                WebDriver driver = new PhantomJSDriver(DesireCaps);

这会引发以下错误: java.lang.IllegalStateException:驱动程序可执行文件不存在:**/home/niti.j/**C:\Users\su.t\Desktop\phantomjs-2.1.1-linux-x86_64\bin\phantomjs

以粗体显示的内容会自动添加到指定的路径中。 请让我知道如何防止这种情况 PhantomjsDriver版本:1.2.1

的pom.xml

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
     <groupId>org.seleniumhq.selenium</groupId>
     <artifactId>selenium-server</artifactId>
     <version>2.53.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.53.0</version>
</dependency>

<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-htmlunit-driver -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-htmlunit-driver</artifactId>
    <version>2.52.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
<!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
<dependency>
    <groupId>org.dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.53.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-exec -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-exec</artifactId>
    <version>1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-support -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-support</artifactId>
    <version>2.53.0</version>
</dependency> 

1 个答案:

答案 0 :(得分:0)

指定的路径可能存在一些问题。仔细检查路径和路径应该是包含驱动程序而不是驱动程序本身的文件夹。

所以 在你的这个位置: C:\ Users \用户su.t \桌面\ phantomjs-2.1.1-Linux的x86_64的\ BIN \ phantomjs

phantomjs应该是包含phantomjs驱动程序的文件夹。如果这个phantomjs在bin文件夹中,请创建您的路径: C:\ Users \用户su.t \桌面\ phantomjs-2.1.1-Linux的x86_64的\ bin中