In this article, we are going to learn how to open the Edge browser in selenium python. To execute the test script we need to launch the Edge browser window. Today we will learn how we can do this by just using a simple script in selenium using the Python language.
We are going to learn to open different browser windows
- How to open/launch Edge browser in selenium python.
- How to invoke Edge browser in selenium python.
- How to open headless Edge browser in selenium python.
Python and selenium Setup on window
Make sure Python and selenium are already installed in our system or else To set up the selenium environment with Python use these steps
1. How to open Edge browser in selenium python
Open Microsoft Edge and type edge://version/ to check for compatible version edge driver as per the version of Brower. Now we can download msedgewebdriver from the official website.
- After Downloading compatible Microsfoftedge driver
- unzip and copy msedgedriver.exe to the python script directory.
- The path of the python script directory for Us is” C:\Users\Admin\AppData\Local \Programs \Python \Python310\Scripts”. It can be different depending on what location we have chosen while installing python.
- Run the below code to automatically Lanuch the Microsoft Edge browser.
from selenium import webdriver
driverEdge = webdriver.Edge()
driverEdge.get('https://bing.com')
print(driver.title)
print(driver.current_url)
driver.quit()
- How to Install selenium on windows Python
- How to install selenium in VSCode
- How to open chrome browser in selenium Python
- How to open Edge browser in selenium Python
- How to open Firefox browser in selenium Python
- Executable path has been deprecated in selenium
- Solved version of ChromeDriver only supports Chrome version 98
- Solved selenium find_element_by_* commands are deprecated
- How to open new tab in Selenium Python
- How to open new window Selenium Python
2. How to Launch headless Microsft Edge in selenium
Follow the above step to download and set up the chrome browser driver.exe. We will follow these steps To open a headless Microsft Edge browser.
- By using options class property specify those parameters,we need while launching the brower.In this example we have passed options.headless =True to open brower without UI or headless
- Driver.get(URL) :to open a specific webpage on chrome brower
- driver.title : To get name of brower on which we running our script.
- driver.Quit() to close the webbrower.
from selenium import webdriver
from selenium.webdriver.edge.options import Options
options = Options()
options.add_argument("headless")
driver = webdriver.Edge(options = options)
driver.quit()
3. Open MS Edge browser without driver Setup
In the above example, we have downloaded the browser driver unzipped, and copied it to the Python script directory. But it is time-consuming, We can automate this work just simply using The webdriver-manager .The first step is to Install the web driver manager by using the command. Let’s understand how to use it in our code to launch Microsoft Edge browsers
pip install webdriver-manager
Python selenium Program to launch MS Edge browser
from selenium import webdriver
import logging
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager(log_level=logging.ERROR).install())
driver.maximize_window()
driver.get("https://google.com")
print('driver Title:',driver.title)
print('Driver name:',driver.name)
print('Driver URL:',driver.current_url)
driver.quit()