2013-08-04 30 views
1

在MacBook Pro中,當我運行以下Selenium時,我得到RuntimeExcepton。java.lang.RuntimeException:無法啓動Selenium會話:

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 

請幫助我..如何解決。

+1

你爲什麼不使用'WebDriver'?如果可能的話,Selenium RC('DefaultSelenium')不應再使用。 http://stackoverflow.com/questions/11535950/difference-between-selenium-rc-and-webdriver – LaurentG

+0

你嘗試過使用另一個webdriver嗎?很明顯硒是無法找到Firefox的。此外,代碼已經過時了,請考慮更新它。 –

回答

0

嘗試這種情況:

DefaultSelenium DS =新DefaultSelenium(新WebDriverCommandProcessor( 「HTTP://:」,新
FirefoxDriver()) );

// ds.start(); - 不要這樣做

ds.open(「/ pdm」);

0

給硒路徑如下圖所示:

->DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*firefox C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "http://"); 
相關問題