Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Repro script for 'no window found' and 'element not visible' errors with SafariDriver
#!/usr/bin/env python
import os
import plistlib
import sys
from selenium import webdriver
from time import sleep
def setup_driver(caps, remote_server=None, use_tp=False):
if remote_server:
# specifying use_tp with a remote server should work as long as you're running 3.8
if use_tp:
caps['safari.options'] = {'technologyPreview': True}
return webdriver.Remote(
if use_tp:
return webdriver.Safari(executable_path='/Applications/Safari Technology')
return webdriver.Safari()
def safari_test(remote_server=None, use_tp=False):
app_path = '/Applications/'
if use_tp is True:
app_path = '/Applications/Safari Technology'
safari_version = plistlib.readPlist(os.path.join(app_path, 'Contents/Info.plist'))['CFBundleShortVersionString']
print "Testing %s, version %s" % (os.path.basename(app_path), safari_version)
driver = setup_driver({'browserName': 'safari'}, remote_server=remote_server, use_tp=use_tp)
# debugging
print "Available window handles: %s" % driver.window_handles
print "'Current' window handle: %s" % driver.current_window_handle
# Both of these methods to set the window size seem to result in a 'no window found' error on Safari 10.1.2
# - on Safari 11.x, these commands seem to just not do anything
# driver.set_window_size(300, 200, driver.current_window_handle)
# driver.set_window_size(1200, 600, 'current')
# On Safari 10.1.2 / 11.0 / 11.0.1 / 11.0.2b2, this seems to return an 'element not visible' error
# (ElementNotVisibleException: An element command could not be completed because the element is not visible on the page)
# This _does work_ with TP 44 (Safari 11.1, WebKit 12605.1.13.2)
cart = driver.find_element_by_class_name('nav-cart-icon')
def main():
# This has 4 different test configs, uncomment out the version you want to test
# Local Safari, installed release version
# Local Safari, TP
# safari_test(use_tp=True)
# Remote Safari running SE on localhost, installed release version
# safari_test(remote_server='http://localhost:4444/wd/hub')
# Remote Safari running SE on localhost, TP
# safari_test(remote_server='http://localhost:4444/wd/hub', use_tp=True)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment