Opening Microsoft Edge in Elevated mode (use case: open via Selenium)

144 Views Asked by At

I am trying to open Ms Edge in Elevated Mode, but I am unable to do so. (Windows 11)

I have tried to open it manually too, but the Elevated option is always set to 'No'.

Image showing Edge Elevated Mode Status:

Image showing Edge Elevated Mode Status

I have tried using the below options via selenium

    admin_edge_options = webdriver.IeOptions()    
    admin_edge_options.use_chromium = True
    admin_edge_options.add_argument('--ie-mode-test')
    admin_edge_options.add_argument('--no-sandbox')
    admin_edge_options.add_argument('--disable-gpu')
    admin_edge_options.add_argument('--disable-software-rasterizer')
    admin_edge_options.add_argument('--disable-dev-shm-usage')
    admin_edge_options.add_argument('--disable-extensions')
    driver = webdriver.Ie(options=admin_edge_options)

Manually I have tried

  1. Run as Administrator:
  • Right-click on the Microsoft Edge shortcut or executable.
  • Choose "Run as administrator" to launch Edge with elevated privileges.
  1. Run after Temporarily disabling windows defender

I tried to perform the same on another Machine (windows 10),facing the same issue.

My config. python 3.12 selenium 4.18.1

Edit 1: Added edge://version screenshot. edge://version screenshot

2

There are 2 best solutions below

4
Yu Zhou On BEST ANSWER

I test and search information and found that it's by design. For chromium-based browsers, it's not recommended to launch the browser Elevated for any reason, as it leads to potential security issues. For these reasons it has built in the behavior to automatically "de-elevate" the browser if it is launched as an administrator.

If you still want to open Edge with elevated privileges, you can try opening it with an administrator account and add --no-sandbox flag to Edge. For example, logging in Windows with an administrator account and use the code below to open Edge in Selenium:

from selenium import webdriver
import time
 
admin_edge_options = webdriver.EdgeOptions()
admin_edge_options.add_argument('--no-sandbox')
 
driver = webdriver.Edge(options=admin_edge_options)
 
driver.get('https://bing.com')
 
time.sleep(25)
driver.quit() 
0
subham chomal On

I figured it out by messing around settings.

  1. Open Edge file location.
  2. Open properties -> compatibility. Click change settings for all users
  3. Check 'Run this program as an Administrator'.
  4. Apply. Ok

Now, if we open Edge it opens with Elevated Status 'Yes'.

If its still opening with Status 'No' . As highlighted by @YuZhou

  1. Open Task Manager
  2. Go to Details
  3. End all Microsoft Edge instances.
  4. Open Edge

Works in Selenium via existing code, no changes.