一、运行代码
driver = webdriver.Edge()
driver.get('https://www.baidu.com')
如果运行上述代码出现以下错误
Traceback (most recent call last):
File "D:\pythonProject\python_bug\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "D:\python\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "D:\python\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/pythonProject/python_bug/Bug_Base/day11_selenium上/selenium_入门.py", line 6, in <module>
driver = webdriver.Edge()
File "D:\pythonProject\python_bug\venv\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 56, in __init__
self.edge_service.start()
File "D:\pythonProject\python_bug\venv\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: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687p
方法一 、
加一个参数 executable_path='msedgedriver.exe'
driver = webdriver.Edge(executable_path='msedgedriver.exe')
time.sleep(2)
# 可以设置等待两秒启动
driver.get('https://www.baidu.com')
运行:
注意,浏览器版本必须是最新版本 !
方法二 、
找到微软浏览器打开设置找到如下标识:
检查是否是最新版本如果不是则则更新到最新,并下载相对应的微软驱动 配置环境变量,环境变量若不会配置可以看我前面的文章。 并且将下载的驱动程序放到微软浏览器的安装文件夹里,配置完成后退出重启下pycharn。