Reputation: 11
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
Upvotes: 1
Views: 5735
Reputation: 2378
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.
Upvotes: 2