MS Edge implementation using Selenium webdriver. Webdriver options not taking effect.

Renuka Bharambe 1 Reputation point
2021-04-06T20:17:11.467+00:00

I have been trying to implement Edge using selenium webdriver.
I tried by passing options to the webdriver instance as well by setting capabilities, but in both cases, it wont work.

def login(self, <arguments>):
open_browser( browser='edge', options=self._set_edge_options(is_hl), executable_path=r"msedgedriver.exe")  

def _set_edge_options(self, is_headless):

        edge_opts= EdgeOptions()
        edge_opts.use_chromium = True

        edge_opts.binary_location="C:\\Windows\\SystemApps\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
        edge_opts.add_argument("headless")
        prefs=("download.default_directory", "C:\\Users\\Lenovo\\Downloads\\Swift_help_Resources")

       edge_opts.add_experimental_option("prefs", prefs)
       return edge_opts

This does not open the browser in headless mode.

Also, i tried using capabilities:

def login(self, <arguments>)
       edge_driver = create_webdriver(driver_name='Edge' , alias= 'egde', capabilities=self._set_edge_options(is_hl))

def _set_edge_options(self, is_headless):
      capability = webdriver.DesiredCapabilities().EDGE.copy()
      capability['acceptSslCerts'] = True
      capability['headless'] = True
      capability['download.default_directory'] = "C:\\Users\\Lenovo\\Downloads\\test-directory"

      return capability

Here, again the browser does not open in headless mode nor is the default download directory set, but the ssl certificate accept capability takes effect.

Microsoft Edge Microsoft Edge development
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2021-04-07T07:15:08.79+00:00

    Hi @Renuka Bharambe

    Are you trying to automate Edge Chromium with Selenium WebDriver using python? And are you trying to use headless mode and change the download path?

    If so, you can refer to the steps below. In your code, you're using MicrosoftEdge_8wekyb3d8bbwe which represents Edge Legacy and it's not right:

    1. Download the correct version of Edge WebDriver from here. Make sure that the Edge WebDriver version is the same as the Edge browser version.
    2. Install the MS Edge Selenium tools using command below: pip install msedge-selenium-tools selenium==3.141
       3. Sample code:  
      
      from msedge.selenium_tools import Edge, EdgeOptions
         options = EdgeOptions()  
         options.use_chromium = True  
         options.add_experimental_option("prefs", {  
           "download.default_directory": r"C:\Users\Lenovo\Downloads\Swift_help_Resources"  
         })  
         options.add_argument("headless")  
         options.add_argument("disable-gpu")  
         driver = Edge(executable_path=r"D:\webdriver89\msedgedriver.exe", options=options)  
         driver.get("https://www.seleniumhq.org/download/");  
         m = driver.find_element_by_link_text("32 bit Windows IE")  
         m.click()  
      

    Note: Change the paths in the code to your owns.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Regards,
    Yu Zhou

    0 comments No comments

  2. Renuka Bharambe 1 Reputation point
    2021-04-28T06:26:02.637+00:00

    Hello @Anonymous
    Thank you for the given steps and apologies for the delay in reply. I followed all the above steps. The options are now being successfully passed to the webdriver instance as seen in the robot logs trace. But i was facing difficulty while passing this webdriver instance to a selenium object as rest of the GUI automation is implemented using this Selenium object.

    We are planning to try and upgrade to Selenium 4 which would make Edge implementation much easier as many of the things there are inbuilt.

    Thank you,
    Renuka.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.