硒webdriver无法正常工作

时间:2016-07-19 15:23:41

标签: python python-3.x selenium selenium-webdriver

Selenium版本:2.53.6 Firefox版本:47.0.1 Chrome版本:51.0.2704.106 m

现在,如果我想这样使用它们:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    driver = webdriver.Firefox()
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 67, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 90, in _start_from_profile_path
    env=self._firefox_env)
  File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

我收到一个错误: FileNotFoundError:[WinError 2]

我甚至检查过两次手册,认为它是编码的正确方法。

那么为什么即使所有内容都更新到最新版本,也无法找到浏览器? 如果我将它们用作人物,Firefox和Chrome就能正常工作。

编辑: 可以在评论中提供错误代码,所以在这里,(srry一些部分是德语,因为它是我的电脑上的主要语言):

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    driver2 = webdriver.Chrome()
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Program Files (x86)\Python35-32\lib\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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

对于Chrome来说:

df = pd.DataFrame(np.random.rand(10, 4),
                           columns=['sd', 'ed', 'sbc', 'ssd'],
                           index=np.arange(2000, 2010))

siPanel = pd.Panel(np.nan, items=np.arange(1998, 2014), major_axis=range(0, 10), minor_axis=range(0, 5))

spiPanel.loc[:, [0], [0]] = df.loc[:, ['sbc']]

奇怪的是我确实将它包含在路径enivornment变量中。我可以输入&#39; chromedriver&#39;在cmd中它找到它....所以python也应该。 还有一个错误: 做最后一件事说了一些奇怪的事情:只允许局部的连接。

1 个答案:

答案 0 :(得分:0)

我不确定是否同时运行两个驱动程序,但至少对于chrome部分,您可能需要将其指向Chrome驱动程序(可以从https://sites.google.com/a/chromium.org/chromedriver/downloads下载

import time
from selenium import webdriver

#driver = webdriver.Chrome('..\..\..\chromedriver.exe')  # Optional argument, if not specified will search path that script is running in.
driver = webdriver.Chrome('E:\AutomatedTesting\PyTestFramework\Automation\selenium\AdditionalDrivers\chromedriver.exe') #this is my path, I haven't worked out how to make the path relative to the script yet
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()