Селен на элементарной ОС не работает с Firefox

#python #selenium #firefox #pycharm #elementary

#python #селен #firefox #pycharm #элементарный-ос

Вопрос:

У меня проблема с Selenium в моей системе. По какой-то причине он не запускает окно браузера Firefox.

Вот шаги, которые я предпринял.

  • Загружено Selenium через pip
  • Загружен драйвер Marionette (gecko)
  • Добавлен каталог загруженного файла в мой ПУТЬ.

Однако я все еще получаю приведенную ниже ошибку.

 /usr/bin/python2.7 /home/keva161/PycharmProjects/selenium_test.py
Traceback (most recent call last):
  File "/home/keva161/PycharmProjects/selenium_test.py", line 21, in <module>
    driver = webdriver.Firefox(capabilities=caps)
  File "/home/keva161/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
    self.service.start()
  File "/home/keva161/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f9bcde911d0>> ignored
  

Сценарий, который я пытаюсь запустить, это:

 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)

driver = webdriver.Firefox()
driver.get('http://saucelabs.com/test/guinea-pig')
driver.quit()
  

Я использую последнюю версию Firefox.

Ответ №1:

PyCharm игнорирует ваш PYTHONPATH, вместо этого он создает его на основе конфигурации (конфигураций) вашего проекта, поэтому вам нужно научить его, где он может найти gecko . Вы можете сделать это любым из этих 2 способов: