I\'m trying to create a cross-browser Python-Selenium
test script. So I need all results to be same no matter which webdriver
(Chrome
or <
Here is function to set the viewport size:
def set_viewport_size(driver, width, height):
window_size = driver.execute_script("""
return [window.outerWidth - window.innerWidth + arguments[0],
window.outerHeight - window.innerHeight + arguments[1]];
""", width, height)
driver.set_window_size(*window_size)
Usage :
from selenium import webdriver
driver = webdriver.Chrome()
# set the viewport size to 800 x 600
set_viewport_size(driver, 800, 600)
# display the viewport size
print driver.execute_script("return [window.innerWidth, window.innerHeight];")