2016-07-30 14 views
37

tôi đang cố gắng để khởi động Mozilla nhưng vẫn Tôi nhận được lỗi này:Selenium sử dụng Java - Đường dẫn đến tài xế thực thi phải được thiết lập bởi hệ thống webdriver.gecko.driver tài sản

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver . The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

Tôi đang sử dụng Selenium 3.0.01 Phiên bản beta và Mozilla 45. Tôi cũng đã thử với Mozilla 47. nhưng vẫn như vậy.

+0

Tôi nghĩ đây không phải là vấn đề trùng lặp, nó xảy ra với' selenium 3' và đó là một vấn đề mới, stacktrace cũng khác. :) –

+0

Bạn cần geckodriver để chạy thử nghiệm selenium 3 trong Firefox –

Trả lời

59

Các liên kết của khách hàng Selenium sẽ cố gắng xác định geckodriver thực thi từ hệ thống PATH. Bạn sẽ cần thêm thư mục chứa tệp thi hành vào đường dẫn hệ thống.

  • On Unix hệ thống bạn có thể làm như sau để thêm nó vào con đường tìm kiếm của hệ thống của bạn, nếu bạn đang sử dụng một vỏ bash tương thích:

    export PATH=$PATH:/path/to/geckodriver 
    
  • On của Windows bạn cần cập nhật biến Hệ thống đường dẫn để thêm đường dẫn thư mục đầy đủ vào tệp thực thi. Nguyên tắc cũng giống như trên Unix.

Tất cả dưới cấu hình cho ra mắt mới nhất firefox sử dụng bất kỳ ngôn ngữ lập trình ràng buộc được áp dụng cho Selenium2 để cho phép rối một cách rõ ràng. Với Selenium 3.0 và sau đó, bạn không cần phải làm bất cứ điều gì để sử dụng Marionette, vì nó được kích hoạt theo mặc định.

Để sử dụng Marionette trong các thử nghiệm của bạn, bạn sẽ cần phải cập nhật khả năng mong muốn của bạn để sử dụng nó.

Java:

Như ngoại lệ được rõ ràng nói rằng bạn cần phải tải về mới nhất geckodriver.exe từ here và thiết lập tải geckodriver.exe con đường mà nó tồn tại trong máy tính của bạn như sở hữu hệ thống với với biến webdriver.gecko.driver trước khi bắt đầu điều khiển con rối và phóng firefox như sau: -

//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code 
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe"); 

//Now you can Initialize marionette driver to launch firefox 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("marionette", true); 
WebDriver driver = new MarionetteDriver(capabilities); 

Và đối với Selenium3 sử dụng như: -

WebDriver driver = new FirefoxDriver(); 

If you're still in trouble follow this link as well which would help you to solving your problem

NET:

var driver = new FirefoxDriver(new FirefoxOptions()); 

Python:

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

caps = DesiredCapabilities.FIREFOX 

# Tell the Python bindings to use Marionette. 
# This will not be necessary in the future, 
# when Selenium will auto-detect what remote end 
# it is talking to. 
caps["marionette"] = True 

# Path to Firefox DevEdition or Nightly. 
# Firefox 47 (stable) is currently not supported, 
# and may give you a suboptimal experience. 
# 
# On Mac OS you must point to the binary executable 
# inside the application package, such as 
# /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin 
caps["binary"] = "/usr/bin/firefox" 

driver = webdriver.Firefox(capabilities=caps) 

của Ruby:

# Selenium 3 uses Marionette by default when firefox is specified 
# Set Marionette in Selenium 2 by directly passing marionette: true 
# You might need to specify an alternate path for the desired version of Firefox 

Selenium::WebDriver::Firefox::Binary.path = "/path/to/firefox" 
driver = Selenium::WebDriver.for :firefox, marionette: true 

JavaScript (Nút.js):

const webdriver = require('selenium-webdriver'); 
const Capabilities = require('selenium-webdriver/lib/capabilities').Capabilities; 

var capabilities = Capabilities.firefox(); 

// Tell the Node.js bindings to use Marionette. 
// This will not be necessary in the future, 
// when Selenium will auto-detect what remote end 
// it is talking to. 
capabilities.set('marionette', true); 

var driver = new webdriver.Builder().withCapabilities(capabilities).build(); 

Sử dụng RemoteWebDriver

Nếu bạn muốn sử dụng RemoteWebDriver trong bất kỳ ngôn ngữ, điều này sẽ cho phép bạn sử dụng Marionette trong Selenium Grid.

Python:

caps = DesiredCapabilities.FIREFOX 

# Tell the Python bindings to use Marionette. 
# This will not be necessary in the future, 
# when Selenium will auto-detect what remote end 
# it is talking to. 
caps["marionette"] = True 

driver = webdriver.Firefox(capabilities=caps) 

của Ruby:

# Selenium 3 uses Marionette by default when firefox is specified 
# Set Marionette in Selenium 2 by using the Capabilities class 
# You might need to specify an alternate path for the desired version of Firefox 

caps = Selenium::WebDriver::Remote::Capabilities.firefox marionette: true, firefox_binary: "/path/to/firefox" 
driver = Selenium::WebDriver.for :remote, desired_capabilities: caps 

Java:

DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 

// Tell the Java bindings to use Marionette. 
// This will not be necessary in the future, 
// when Selenium will auto-detect what remote end 
// it is talking to. 
capabilities.setCapability("marionette", true); 

WebDriver driver = new RemoteWebDriver(capabilities); 

NET

DesiredCapabilities capabilities = DesiredCapabilities.Firefox(); 

// Tell the .NET bindings to use Marionette. 
// This will not be necessary in the future, 
// when Selenium will auto-detect what remote end 
// it is talking to. 
capabilities.SetCapability("marionette", true); 

var driver = new RemoteWebDriver(capabilities); 

Lưu ý: Cũng giống như các trình điều khiển khác có sẵn để Selenium từ các nhà cung cấp trình duyệt khác, Mozilla đã phát hành bây giờ là một thực thi mà sẽ chạy cùng với trình duyệt. Theo dõi this để biết thêm chi tiết.

You can download latest geckodriver executable to support latest firefox from here

+2

Cảm ơn bạn rất nhiều.Điều này hoạt động hoàn hảo Nhưng chỉ để biết thông tin, geckodriver này là gì? Tôi đã làm việc với selenium cho đôi khi và tôi đã làm Tuy nhiên, bây giờ tôi vừa mới thay đổi máy của mình và gặp lỗi này – Reema

+1

@Reema Giống như các trình điều khiển khác có sẵn cho Selenium từ các nhà cung cấp trình duyệt khác, Mozilla đã phát hành một tệp thực thi sẽ chạy cùng với trình duyệt. alook cho chi tiết hơn..https: //developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/IWebDriver –

+0

Cách đặt đường dẫn cho geckodriver cho tất cả các nền tảng? Ứng dụng Java của tôi được xây dựng trên các hệ thống khác nhau. – Michal

10
  1. Tải tắc kè lái xe từ trang web seleniumhq (Bây giờ nó là trên GitHub và bạn có thể tải nó từ Here).
    1. Bạn sẽ có một zip (hoặc tar.gz) để trích xuất nó.
    2. Sau khi trích xuất, bạn sẽ có tệp geckodriver.exe (thực thi thích hợp trong linux).
    3. Tạo thư mục trong C: tên SeleniumGecko (Hoặc phù hợp)
    4. Copy và Paste geckodriver.exe để SeleniumGecko
    5. Đặt đường dẫn cho tài xế tắc kè như sau

.

System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.10.0-win64\\geckodriver.exe"); 
WebDriver driver = new FirefoxDriver(); 
+0

Cảm ơn! Bạn chỉ cần giữ nó đơn giản. Tôi chỉ cần điều đó để giải quyết vấn đề của mình !! Công trinh ! –

1

đang Selenium WebDriver Java:

Tải Gecko điều khiển từ https://github.com/mozilla/geckodriver/releases dựa trên nền tảng của bạn. Giải nén nó ở một vị trí theo sự lựa chọn của bạn. Viết đoạn mã sau:

System.setProperty("webdriver.gecko.driver", "D:/geckodriver-v0.16.1-win64/geckodriver.exe"); 
WebDriver driver = new FirefoxDriver(); 
driver.get("https://www.lynda.com/Selenium-tutorials/Mastering-Selenium-Testing-Tools/521207-2.html"); 
+0

Vị trí có thể thay đổi từng cá nhân. Tôi trích xuất nó trên ổ đĩa D –

0

Mỗi dịch vụ điều khiển trong selen cuộc gọi đoạn code tương tự (Sau đây là mã cụ firefox) trong khi tạo ra các đối tượng lái xe

@Override 
protected File findDefaultExecutable() { 
     return findExecutable(
     "geckodriver", GECKO_DRIVER_EXE_PROPERTY, 
     "https://github.com/mozilla/geckodriver", 
     "https://github.com/mozilla/geckodriver/releases"); 
    } 

bây giờ cho người lái xe mà bạn muốn sử dụng , bạn phải thiết lập thuộc tính hệ thống với giá trị của đường dẫn đến trình điều khiển thực thi.

cho firefox GECKO_DRIVER_EXE_PROPERTY = "webdriver.gecko.trình điều khiển "và điều này có thể được đặt trước khi tạo đối tượng trình điều khiển như bên dưới

System.setProperty("webdriver.gecko.driver", "./libs/geckodriver.exe"); 
WebDriver driver = new FirefoxDriver(); 
Các vấn đề liên quan