2013-04-25 29 views
6

tôi liên tục nhận được unsupportedCommandException khi tôi chạy đoạn mã sau:Không thể gọi FirefoxDriver constructor

System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox\\Firefox.exe"); 
    FirefoxProfile firefoxProfile = new FirefoxProfile(); 

    String domain = "extensions.firebug."; 
    firefoxProfile.setPreference("app.update.enabled", false); 
    firefoxProfile.addExtension(new File("D:\\\\firebug-1.11.2-fx.xpi")); 
    firefoxProfile.setPreference(domain + "currentVersion", "1.11.2"); 
    firefoxProfile.setPreference("extensions.firebug.cookies.enableSites", true); 
    firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "on"); 

    firefoxProfile.setPreference(domain + "framePosition", "bottom"); 
    firefoxProfile.setPreference(domain + "defaultPanelName", "cookies"); 

    WebDriver driver = new FirefoxDriver(firefoxProfile); 
    driver.get("http://www.google.com/webhp?complete=1&hl=en"); 
    WebElement query = driver.findElement(By.name("q")); 

phiên bản Firefox: 20,0, firebug 1.11.2.

Thông báo lỗi Tôi nhận được là như dưới:

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Bad request 

Command duration or timeout: 437 milliseconds 
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22' 
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24' 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) 
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216) 
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179) 
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:96) 
    at com.vinit.tiwari.TestCookieFirefox.main(TestCookieFirefox.java:48) 

Trả lời

12

Điều này có thể làm gì với cấu hình máy của bạn.

Nếu bạn có một dòng như thế này:

127.0.0.1 domain1 domain2 domain3 localhost

Thay đổi nó để:

127.0.0.1 localhost domain1 domain2 domain3

+1

này hiện đang nộp ở đây: https://code.google.com/p/selenium/issues/detail?id=3280 – desau

1

mỗi câu trả lời chấp nhận từ @APWorsley, vấn đề này có thể được gây ra bởi nhiều bí danh cho bộ điều hợp vòng lặp trong tệp /etc/hosts của bạn.

Nếu bạn không có quyền truy cập thuận tiện để xóa hoặc sắp xếp lại bí danh (có thể không có quyền truy cập root hoặc Rối được ghi lại thường xuyên), vì Selenium issue #3280 hiện đã được khắc phục, có quyền truy cập cấu hình thuộc tính cho phép kết nối từ các tên bí danh khác nhau trong tệp lưu trữ của bạn.

Đầu tiên thu thập tất cả các bí danh có thể cho loopback/localhost/127.0.0.1 trong tệp lưu trữ của bạn, sau đó đặt thuộc tính Trình điều khiển Firefox. Ví dụ, nếu bạn có localhost cộng localhost.localdomain, bạn có thể cấu hình trình điều khiển như thế này:

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost,localhost.localdomain"); 
WebDriver driver = new FirefoxDriver(profile); 
+0

Cảm ơn. Tôi có cùng một vấn đề mà con rối cứ viết lại tập tin này. Có cách nào để vĩnh viễn thay đổi cấu hình này cho firefox không? Bằng cách đó tôi không phải cập nhật mã java ở mọi nơi. – dganesh2002

Các vấn đề liên quan