Python,web驱动程序错误(Selenium)

2024-05-14 00:45:58 发布

您现在位置:Python中文网/ 问答频道 /正文

    import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)

我发现了错误:

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

我不知道发生了什么,因为我已经进口了硒。


Tags: fromimportgettimedriverseleniumactionelement
2条回答

要么在webdriver.Chrome中提供ChromeDriver路径,要么提供path变量

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driverLocation = 'D:\Drivers\chromedriver.exe' #if windows
driver = webdriver.Chrome(driverLocation) 
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)

在不更改代码eevn单行的情况下消除此异常的最佳方法是将chromedriver.exe(或其他浏览器驱动程序文件)添加到Python中

  1. site_packages/scripts directory for windows
  2. dist_package/scripts for Linux

请检查这个解决方案,它有效。

相关问题 更多 >