简体   繁体   中英

How to initiate Edge (Chromium) browsing session using Selenium and Python

I am getting following error while running driver Edge opens but then this error pops up and cant run rest of the code

MY CODE

from selenium import webdriver

driver = webdriver.Edge()
driver.get("https://stackoverflow.com")

Traceback (most recent call last):
  File "C:\Users\Jawad Azhar Ch\Documents\1.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

As per the documentation in Use WebDriver (Chromium) for test automation to initiate a Microsoft Edge (Chromium) Browsing Context using WebDriver you need to follow the steps mentioned below:

  • Install Microsoft Edge (Chromium) : Ensure that you have installed Microsoft Edge (Chromium) . To confirm that you have Microsoft Edge (Chromium) installed, go to edge://settings/help in the browser, and verify the version number is Version 75 or later.
  • Download Microsoft Edge Driver : To begin automating tests, use the following steps to ensure that the WebDriver version you install matches your browser version.
    • Go to edge://settings/help to get the version of Edge.

边缘版本.png

边缘驱动安装.png


Demonstration

You can use the following solution:

  • Code Block:

     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))
  • Console Outout:

     Page title is: Settings
  • Browser Snapshot:

微软边缘

I don't think you're importing everything required among some other issues, refer to this: https://www.browserstack.com/guide/launch-edge-browser-in-selenium

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM