Selenium无法点击链接

时间:2017-10-24 18:16:38

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

我一直试图在python 3.6中使用Selenium来点击一个链接,但我一直得到同样的错误。我已经安装了plenium并在Aptana中使用此代码

Traceback (most recent call last):
  File "C:\Users\noart\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\noart\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\noart\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "C:\Users\noart\Desktop\Exercize Files Beginner\Ch2\Drivers_Ed_Made_Easy.py", line 4, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\noart\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "C:\Users\noart\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

感谢您提供任何帮助!

1 个答案:

答案 0 :(得分:0)

从你的例外:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

似乎你没有设置geckodriver的可执行路径。

尝试:

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'\yourPathTo\geckodriver.exe')
driver.get("https://www.google.co.uk/")
相关问题