0

The target of this project is to automate checking sites with Microsoft edge browser using selenium-python i downloaded the webdriver for the edge legacy from this link and i went for the latest release 17134 extracted it with out any problems now lets say i want to visit facebook in an automated way with firefox using the geckodriver

firefox code sample with selenium

from  selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

# setting up headless option for faster execution
options = Options()
options.headless = True


browser = (webdriver.Firefox(options=options))
browser.get('https://www.facebook.com/')

but when I try to use Microsoft edge that is built in windows 10 I get an attribute error

from  selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.edge.options import Options



options = Options()
options.headless = True

#browser = webdriver.edge(options=options)
browser = webdriver.edge()

ps : when I uncomment this part (browser = webdriver.edge(options=options)) I get module not found error

what is the right way to call Microsoft edge browser , or what I am doing wrong

Weed Cookie
  • 579
  • 1
  • 3
  • 11

3 Answers3

5

when I use Edge and try to make Edge headless. I also find it hard to do that with slight changes as Chrome. And I refer to the official documentation and get a official solution. Besides selenium, you need to install msedge-selenium-tools, just pip install itpip install msedge-selenium-tools. And use Edge Class in msedge tools. Just like:

from msedge.selenium_tools import Edge
driver = Edge(executable_path='where')

And if we want to make Edge headless, we need to use EdgeOptions Class which selenium.webdriver doesn't offer. selenium.webdriver only provides us with ChromeOptions, FirefoxOptions and Ie's. EdgeOptions is in a separated package msedge.selenium_tools.Then we add argument as what we do on Firefox or Chrome. Before that, we need to set the attribute use_chromium as True. The whole codes:

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='where', options=edge_options)

Hope it helps. Sorry for my awkward explaination.

  • does this require edge chromium to work, i would love to run this with out installing any additional browsers – Weed Cookie Sep 07 '20 at 10:39
  • @WeedCookie The old Edge browser? will be going out of support anyway. I assume you are wanting to test on the old one that may well not be security patched? –  May 13 '21 at 09:27
2

I am using this WebDriver Package. Works perfectly. This package auto-download and runs your system-compatible browser smoothly. If you want to install and run a specific version, that is also possible. To know the instructions click here.

This code is for Selenium 4 [Python 3.10.*]

  class MyEdge:
      def get_browser(self):
          options = webdriver.EdgeOptions()
          # If you want to avoid popup browser use '--headless'
          options.add_argument('--headless')
          # Ref: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python#using-chromium-specific-options
          self.driver = webdriver.Edge(options= options,service=Service(EdgeChromiumDriverManager().install()))
          return self.driver

More optional arguments: --headless, --no-sandbox, '--disable-gpu', '--window-size=1280x1696', '--user-data-dir=/tmp/user-data', '--hide-scrollbars', '--enable-logging', '--log-level=0', , '--single-process', '--data-path=/tmp/data-path', '--ignore-certificate-errors', '--homedir=/tmp', '--disk-cache-dir=/tmp/cache-dir'

Make sure to impore:

# Import
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
0

I try to refer to the official documentation for WebDriver for Microsoft Edge (EdgeHTML). But I did not get any information about the Headless mode in it.

WebDriver (EdgeHTML)

I also try to refer to some old threads to find any information on this topic. It looks like we cannot use the Headless mode with the MS Edge legacy browser.

Headless Edge driven through Selenium by C#

I found one article that also said that 'User cannot use IE10, IE11, Edge, Opera & Safari for headless testing.'

Headless Browsers Testing using Selenium Webdriver

From the above references, it looks like you cannot use Headless mode with the MS Edge legacy browser.

As a workaround, I suggest you try to make a test with the MS Edge Chromium browser. I found that it supports Headless mode.

Using Chromium-Specific Options

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19
  • the problem i am facing is that i can't change the options of the webdriver to make it headless if i include options inside the brackets i get a typeerror unexpected keyword argument options – Weed Cookie Apr 28 '20 at 18:13
  • Please see the updated answer. It may help to clarify the issue. Let me know if you have further questions. – Deepak-MSFT Apr 29 '20 at 06:11