如何使用 Selenium 和 Python 初始化 Edge (Chromium) 浏览器会话
How to initiate Edge (Chromium) browsing session using Selenium and Python
我在 运行ning 驱动程序时遇到以下错误
Edge 打开但随后弹出此错误并且无法 运行 其余代码
我的代码
from selenium import webdriver
driver = webdriver.Edge()
driver.get("https://whosebug.com")
Traceback (most recent call last):
File "C:\Users\Jawad Azhar Ch\Documents.CODING\idm dload\id.py", line 4, in <module>
driver = webdriver.Edge()
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 61, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Unknown error
除其他问题外,我认为您没有导入所需的所有内容,请参阅:
https://www.browserstack.com/guide/launch-edge-browser-in-selenium
根据 Use WebDriver (Chromium) for test automation to initiate a Microsoft Edge (Chromium) Browsing Context using 中的文档,您需要执行以下步骤:
- Install Microsoft Edge (Chromium): Ensure that you have installed Microsoft Edge (Chromium)。要确认您已安装 Microsoft Edge (Chromium),请在浏览器中转到
edge://settings/help
,并验证版本号是 75 版 或更高版本。
- Download Microsoft Edge Driver:要开始自动化测试,请使用以下步骤确保您安装的 WebDriver 版本与您的浏览器版本匹配。
- 转到
edge://settings/help
获取 Edge 的版本。
- 导航至 Microsoft Edge Driver downloads 页面并下载与 Edge 版本号匹配的驱动程序。
示范[=37=]
您可以使用以下解决方案:
代码块:
from selenium import webdriver
driver = webdriver.Edge(executable_path=r'C:\WebDrivers\msedgedriver.exe')
driver.get('edge://settings/help')
print("Page title is: %s" %(driver.title))
控制台输出:
Page title is: Settings
浏览器快照:
我在 运行ning 驱动程序时遇到以下错误 Edge 打开但随后弹出此错误并且无法 运行 其余代码
我的代码
from selenium import webdriver
driver = webdriver.Edge()
driver.get("https://whosebug.com")
Traceback (most recent call last):
File "C:\Users\Jawad Azhar Ch\Documents.CODING\idm dload\id.py", line 4, in <module>
driver = webdriver.Edge()
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 61, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Jawad Azhar Ch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Unknown error
除其他问题外,我认为您没有导入所需的所有内容,请参阅: https://www.browserstack.com/guide/launch-edge-browser-in-selenium
根据 Use WebDriver (Chromium) for test automation to initiate a Microsoft Edge (Chromium) Browsing Context using
- Install Microsoft Edge (Chromium): Ensure that you have installed Microsoft Edge (Chromium)。要确认您已安装 Microsoft Edge (Chromium),请在浏览器中转到
edge://settings/help
,并验证版本号是 75 版 或更高版本。 - Download Microsoft Edge Driver:要开始自动化测试,请使用以下步骤确保您安装的 WebDriver 版本与您的浏览器版本匹配。
- 转到
edge://settings/help
获取 Edge 的版本。
- 转到
- 导航至 Microsoft Edge Driver downloads 页面并下载与 Edge 版本号匹配的驱动程序。
示范[=37=]
您可以使用以下解决方案:
代码块:
from selenium import webdriver driver = webdriver.Edge(executable_path=r'C:\WebDrivers\msedgedriver.exe') driver.get('edge://settings/help') print("Page title is: %s" %(driver.title))
控制台输出:
Page title is: Settings
浏览器快照: