With Chrome you can add options when creating the driver. You just do
options = Options()
options.headless = True
driver = webdriver.Chrome(PATH\TO\DRIVER, options=options)
But for some reason when trying to do the same with Microsoft Edge
options = Options()
options.headless = True
driver = webdriver.Edge(PATH\TO\DRIVER, options=options)
I get this error
TypeError: __init__() got an unexpected keyword argument 'options'
For some reason Edge's driver doesn't accept any other parameters than the file path. Is there any way to run Edge headless and add more options just like in Chrome?
It is quite simple to run your tests in the headless mode. You need simply to add the "--headless" argument to the EdgeOptions object. NOTE: Make sure to download the correct version of Edge driver and copy it to the output folder. Also, you need to install the latest version of the Microsoft.
Selenium WebDriver is an open-source testing framework that can be used on any platform, and provides language bindings for Java, Python, C#, Ruby, and JavaScript. To use WebDriver to automate Microsoft Edge, if you use Selenium, you must use Selenium 4, which has built-in support for Microsoft Edge (Chromium).
Yes, Selenium supports headless testing. In older versions of Selenium, we used the HTMLUnitDriver mainly, a headless driver providing a Non-GUI implementation of Selenium WebDriver.
Open Microsoft Edge Webdriver page using this link – https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Click on Downloads and from the list of different versions of Edge drivers, download the latest one or as per your requirement. This will download the msi file.
options = EdgeOptions()
options.use_chromium = True
options.add_argument("headless")
options.add_argument("disable-gpu")
Try above code , you have to enable chromium to enable headless
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python
This works only for new edge chromium not for edge legacy versions . In legacy versions headless is not supported
Full code
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
# make Edge headless
edge_options = EdgeOptions()
edge_options.use_chromium = True # if we miss this line, we can't make Edge headless
# A little different from Chrome cause we don't need two lines before 'headless' and 'disable-gpu'
edge_options.add_argument('headless')
edge_options.add_argument('disable-gpu')
driver = Edge(executable_path='youredgedriverpath', options=edge_options)
webdriver.Edge
does not accept any options
so i switched it to the following:
It worked for me.
# imports
from selenium import webdriver
from msedge.selenium_tools import EdgeOptions
# options
options = EdgeOptions()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("disable-gpu")
browser = webdriver.Chrome(
executable_path="resources/msedgedriver.exe", options=options)
browser.get(gen_token)
The version of Microsoft Edge that I am using is :
Microsoft Edge Version 89.0.774.57 (Official build) (64-bit)
This worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With