1

OS - Windows 10 Selenium - 4 Python - 3.9.7 Browser - MS Edge (v97) Edge Driver (v97)

Whilst the following code works, albeit with an error thrown, it seems (according to MS) that the Selenium 4 approach is to use 'official EdgeOptions and EdgeDriver classes from the OpenQA.Selenium.Edge namespace':

import unittest
from selenium import webdriver
from selenium.webdriver.edge import service
from selenium.webdriver.edge.options import Options

class Login(unittest.TestCase):

    def setUp(self):
        
        s=service.Service(r'C:\Users\Path_to_driver\msedgedriver.exe')
        self.driver = webdriver.Edge(service=s)
        url = "https://my_website"
        self.driver.get(url)

Thing is, as a newbie to Python OO and Selenium, i'm badly floundering on how to do this and all of my web searches have failed to provide an answer that I can understand. I can't even find OpenQA.Selenium.Edge, EdgeOptions or EdgeDriver, which is not a good start! :-/

Ideally i'd like to use the Selenium 4 method and so i'd be really grateful if anyone can provide me with some pointers. TIA

3
  • The "OpenQA.Selenium.Edge namespace" is a C#/.NET concept. It doesn't apply to Python. If it works as is, then you have nothing to worry about. Commented Jan 21, 2022 at 0:00
  • Ah OK, thanks Tim Commented Jan 21, 2022 at 15:38
  • May I know if you have got any chance to check my answer? I am glad to help if you have any other questions. Commented Jan 28, 2022 at 2:49

1 Answer 1

2

I agree with @TimRoberts mentioned, but if you want to implement your requirement in Python, you can also use [msedge-selenium-tools] for Selenium 3 (https://pypi.org/project/msedge-selenium-tools/).

Simple code:

from msedge.selenium_tools import Edge, EdgeOptions

# load the desired webpage
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"

driver = Edge(options = edge_options, executable_path=r"C:\Users\Administrator\Desktop\msedgedriver.exe")
driver.get('<your website url>')

Edit:

Or you can use the built-in EdgeOptions in Selenium 4. Simple code below:

from selenium import webdriver
from selenium.webdriver.edge import service

edgeOption = webdriver.EdgeOptions()
edgeOption.use_chromium = True
edgeOption.add_argument("start-maximized")
edgeOption.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
s=service.Service(r'C:\Users\Administrator\Desktop\msedgedriver.exe')
driver = webdriver.Edge(service=s, options=edgeOption)
driver.get("<your website url>")

Note: msedge-selenium-tools should be uninstall to use Selenium 4.

Sign up to request clarification or add additional context in comments.

2 Comments

Many of the solutions suggest that approach, but I don't believe it is appropriate to Selenium 4!? This from MS: If you use Selenium 4, you don't need to use Selenium Tools for Microsoft Edge. Selenium Tools for Microsoft Edge are for Selenium 3 only. It's this that sent me around in circles trying different things, but failing miserably. I was hoping to determine a W3C way of doing it, as that seems to be the approach.
Well, if this is the case, you could use the built-in EdgeOptions in Selenium webdriver. Simple refer to my edited answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.