0
from selenium import webdriver

driver = webdriver.Edge(r"/Users/pranav/Downloads/edgedriver_mac64/msedgedriver")

在运行这段代码时,我希望 Edge 会像 Chrome 一样弹出,但它并没有发生。我收到以下错误:

Traceback (most recent call last):
  File "/Users/pranav/Documents/Python/Scripts/Edge Auto.py", line 3, in <module>
    driver = webdriver.Edge(r"/Users/pranav/Downloads/edgedriver_mac64/msedgedriver")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/edge/webdriver.py", line 61, in __init__
    RemoteWebDriver.__init__(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found
4

1 回答 1

0

要使用边缘,您还需要 msedge selenium 工具。看这里

pip install msedge-selenium-tools

安装包后,试试这个:

from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.keys import Keys

# Launch Microsoft Edge (Chromium)
options = EdgeOptions()
options.use_chromium = True
driver = Edge(options = options)

driver.get ("https://www.google.com")
于 2021-03-04T15:45:49.767 回答