How do I resize the window in Chrome and Firefox when testing with Selenium?

前端 未结 2 1795
小鲜肉
小鲜肉 2021-01-12 14:41

We created extensions for Chrome, Firefox and Safari and we want to test our extensions with Selenium. We have an Ubuntu server and I installed Firefox and Chrome in it (wit

相关标签:
2条回答
  • For Chromejust add before "webdriver.Chrome" init:

    chrome_options.add_argument("--window-size=1920x1080")
    

    For all browsers:

    There is an official selenium python binding for that: http://selenium.googlecode.com/git/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.set_window_size

    driver.set_window_size(1920, 1080)
    

    or

    driver.maximize_window()
    

    or with javascript

    driver.execute_script("window.resizeTo(1920,1080)")
    
    0 讨论(0)
  • 2021-01-12 15:17
    driver.set_window_size(width, height) 
    

    If you don't know the width and height use the How Big Is My Browser website.

    0 讨论(0)
提交回复
热议问题