1

在 MacBook Pro 中,当我运行以下 Selenium 时,我得到了 RuntimeException。

import com.thoughtworks.selenium.DefaultSelenium;

public class Test {

   public static void main(String[] args) {
           DefaultSelenium selenium=new DefaultSelenium("localhost", 4444,"*firefox ","http://");
           selenium.start();
           selenium.open("http://google.co.in");
           selenium.windowMaximize();
           selenium.type("gbqfq", "selenium");
           selenium.click("gbqfb");
   }

}

例外:

Exception in thread "main" java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: java.lang.RuntimeException: java.lang.RuntimeException: Firefox 3 could not be found in the path!
Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment
variable, or explicitly specify a path to Firefox 3 like this:
*firefox3 /blah/blah/firefox-bin
       at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
       at Test.main(Test.java:8)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: java.lang.RuntimeException: java.lang.RuntimeException: Firefox 3 could not be found in the path!
Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment
variable, or explicitly specify a path to Firefox 3 like this:
*firefox3 /blah/blah/firefox-bin
       at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
       at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
       at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
       at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
       at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
       ... 1 more

请帮助我..如何解决。

4

3 回答 3

0

给出 Selenium 路径,如下所示:

->DefaultSelenium  selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "http://");
于 2014-10-30T09:26:12.357 回答
0

尝试这个:

DefaultSelenium ds = new DefaultSelenium(new WebDriverCommandProcessor("http://:",new
FirefoxDriver()));

// ds.start(); - 不要这样做

ds.open("/pdm");

于 2013-08-22T06:56:13.830 回答
0

您需要提供 firefox 配置文件路径,以便 selenium 可以使用它来实例化浏览器。

OS X Firefox 配置文件位置

Selenium w/ Firefox Profile 1

Selenium w/ Firefox Profile 2

于 2013-08-04T19:13:28.627 回答