【问题标题】:My simple ghostdriver program is not running?我简单的 ghostdriver 程序没有运行?
【发布时间】:2015-02-13 10:36:33
【问题描述】:

让我告诉你,我是使用GhostDriver的新手

我成功下载PhantomJS并且我已经将我的路径设置为环境变量,现在我正在尝试运行这个简单的程序:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PhantomJSTest {

   private WebDriver driver;

   private static final By ABOUT_TAB = By.linkText("About");
   private static final By ROADMAP_LINK = By.xpath("//a[text() = 'Roadmap']");
   private static final By HELP_LINK = By.xpath("//a[text() = 'Help']");

   @BeforeClass
   private void initialize() {
      driver = new PhantomJSDriver();
      driver.navigate().to("http://www.seleniumhq.org/");
   }

   @Test
   public void verifySomething() {
      driver.findElement(ABOUT_TAB).click();
      assertThat(driver.findElement(ROADMAP_LINK).isDisplayed(), is(true));
      assertThat(driver.findElements(HELP_LINK).isEmpty(), is(true));
   }

   @AfterClass
   private void quit() {
      driver.quit();
   }
}

我试图运行它,但它说:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at smsRobot.MyProgram.main(MyProgram.java:24)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

请帮忙:(

将不胜感激!

更新


下载selenium-common.jar后,出现这个错误:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:237)
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:182)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at smsRobot.MyProgram.main(MyProgram.java:24)

【问题讨论】:

    标签: java selenium phantomjs ghostdriver


    【解决方案1】:

    您需要像这样设置 phantomDriver 可执行文件的路径:

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true); // enabled by default
    caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        "path/to/your/phantomjs.exe"
    );
    
    driver = new PhantomJSDriver(caps);
    driver.navigate().to("http://www.seleniumhq.org/");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-10
      • 2014-09-26
      • 1970-01-01
      • 2014-08-31
      • 2014-12-02
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      相关资源
      最近更新 更多