Search code examples
pythonselenium-webdriverbrowsermicrosoft-edgewindow-size

How to define windows size for Microsoft Edge with Selenium in Python?


I am trying to write a python program that visits a site hosted by me for testing and development purposes, I would like to use Microsoft Edge browser only for this task but I can't seem to figure out how to run the script headless so that it would consume fewer resources, I did my research but Edge browser does not seem to have a headless option as far as I understand correct me if I am wrong please, so is there any way to size the browser window that pops up on my screen to zero dimensions, if so does it use fewer resources since there is nothing to render?

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

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


engine = webdriver.Edge()
#engine = webdriver.Edge(executable_path="path/to/executable")

engine.get('my_site_link_goes_here')


assert 'title' in engine.title


print ("Done")

when I run this script everything works as expected but I would like to make it close to headless as much as possible

ps: I can only use Edge browser for testing


Solution

  • Selenium webdriver does not provide any method for minimizing the browser, there is no such direct method. You need to use resize method to minimize the browser.

    Dimension d = new Dimension(300,1080);
    #Resize current window to the set dimension
    driver.manage().window().setSize(d);