How to resize Selenium browser window to emulate a phone screen using Python?

  • I want to be able to resize the Selenium browser window to emulate a phone screen, is there a way to do that? Small enough (340,695)

    This is what I have so far, no luck

    from selenium.webdriver.common.keys import Keys
    from time import sleep
    chromedriver_path = '../chromedriver' # Change this to your own chromedriver path!
    webdriver = webdriver.Chrome(executable_path=chromedriver_path)
    webdriver.set_window_size(340,695) # Makes the chrome browser, mobile viewport
    webdriver.get('') # Visit Instagram

  • Maybe using webdriver as a variable name for the webdriver is confusing. Try using

    driver = webdriver.Chrome(executable_path=chromedriver_path)

    And then you can resize window size with the following

    driver.set_window_size(340, 695)

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2