FileNotFoundError:[WinError 2]系统找不到与python一起使用Selenium指定的文件

时间:2018-08-21 12:35:27

标签: python selenium selenium-webdriver python-unittest

我正在将Selenium与Python结合使用,当我尝试对单元测试进行测试时 在Pycharm IDE中,由于我是python的Selenium的初学者,因此出现错误,无法找到解决方案。

这是我使用的代码:

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class MyTestCase(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_login(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source


if __name__ == '__main__':
    unittest.main()



-------------------------------------
-------------------------------------
Here is the Error I am getting :  

Ran 1 test in 0.053s

FAILED (errors=1)

Error
Traceback (most recent call last):
  File "C:\python\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\python\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\python\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\python\lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "C:\python\lib\unittest\case.py", line 611, in run
    self.setUp()
  File "C:\Users\Pardeep\PycharmProjects\modbus\modbus\modbus.py", line 7, in setUp
    self.driver = webdriver.Firefox()
  File "C:\python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 157, in __init__
    self.service.start()
  File "C:\python\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 




Hi I am using Selenium with Python and when I trying to sun the Unittest

在Pycharm IDE中,我遇到了错误,无法找到解决方案,因为我是使用python的Selenium的初学者。

0 个答案:

没有答案