Workaround for Set Window Size Issue on Safari 10.1 Webdriver
If you are using Safari 10.0 and the webdriver provided by Apple for browser automation, don’t upgrade to Safari 10.1. If you have upgraded Safari, you probably have noticed that set window size is not working. To work around the issue, you need the help of AppleScript.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import os from selenium import webdriver browser = 'Safari' # or 'Chrome' driver = getattr(webdriver, browser)() if browser == 'Safari': x, y = 0, 22 cmd = "osascript -e 'tell application \"Safari\" to set bounds of front window to {%d, %d, %d, %d}'" \ % (x, y, width+x, height+y) os.system(cmd) else: driver.set_window_size(width, height) |