Перейти к содержимому

Timich

Регистрация: 24 окт 2016
Offline Активность: 03 ноя 2023 06:26
-----

Мои темы

Перестал работать Selenium WebDriver в Firefox

26 октября 2016 - 08:28

Добрый день!

 

Приключилась такая проблема. После перерыва решил возобновить изучение автотестирования в связке Selenium WebDriver-Python. И теперь, при попытке запустить тест в PyCharm отображается такая ошибка:

 

env\lib\site-packages\selenium\webdriver\common\service.py:64: in start
    stdout=self.log_file, stderr=self.log_file)
c:\users\user1\appdata\local\programs\python\python35-32\Lib\subprocess.py:947: in __init__
    restore_signals, start_new_session)
c:\users\user1\appdata\local\programs\python\python35-32\Lib\subprocess.py:1224: in _execute_child
    startupinfo)
E   FileNotFoundError: [WinError 2] Не удается найти указанный файл
 
During handling of the above exception, another exception occurred:
test1.py:8: in <module>
    driver = webdriver.Firefox(capabilities=firefox_capabilities)
env\lib\site-packages\selenium\webdriver\firefox\webdriver.py:135: in __init__
    self.service.start()
env\lib\site-packages\selenium\webdriver\common\service.py:71: in start
    os.path.basename(self.path), self.start_error_message)
E   selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.47 seconds ===========================
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03A8CDB0>>
Traceback (most recent call last):
  File "C:\testSelenium\env\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
  File "C:\testSelenium\env\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
AttributeError: 'Service' object has no attribute 'process'
 
 
Сам тест вот такой:
 
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = 'C:\Program Files (x86)\Mozilla Firefox'
import time, unittest
driver = webdriver.Firefox(capabilities=firefox_capabilities)


class test1(unittest.TestCase):
def setUp(self):
self.wd = webdriver.Firefox(capabilities=firefox_capabilities)
self.wd.implicitly_wait(60)

def test_test1(self):
success = True
wd = self.wd
wd.get("https://mail.ru/")
wd.find_element_by_id("q").click()
wd.find_element_by_id("q").clear()
wd.find_element_by_id("q").send_keys("привет")
wd.find_element_by_id("search__button__wrapper__field").click()
self.assertTrue(success)

def tearDown(self):
self.wd.quit()


if __name__ == '__main__':
unittest.main()
 
 
Надо отметить, что перед запуском этого теста, я произвел обновление Selenium на 3-ю версию, установил geckodriver (v0.11.1) в директорию браузера и прописал путь до него в переменной Path (перед этим переименовал в wirex, как было сказано вот тут). Использовал браузер FF 49.0.2. Версия Python 3.5.1.