环境:Mac OS X Yosemite 10.10.4下, Safari 8
Step 1:第一次运行SafariDriver时,先找到WebDriver extension的安装路径,比如/Users/extrabux/library/safari/extensions;
Step 2:然后在Java程序中添加:
System.setProperty("webdriver.safari.driver", "/Users/extrabux/library/safari/extensions");
driver = new SafariDriver();
Step 3:运行程序,如果执行正常,说明程序自动安装SafariDriver extension正常了,否则如果报如下异常,继续Step 4
WebDriverException: Message: Failed to connect to SafariDriver after 10065 ms
java.util.concurrent.ExecutionException:
org.openqa.selenium.WebDriverException:
java.lang.reflect.InvocationTargetException
Step 4:上面异常通常出在安装SafariDriver上,即运行SafariDriver之前需要给safari安装一个 WebDriver extension,名字是WebDriver.safariextz,如果安装不成功则执行不成功,mac下的路径应该是/Users/extrabux/library /safari/extensions;
Step 5:打开http://selenium-release.storage.googleapis.com /index.html?path=2.48,因为我用的selenium是2.48版的,所以在这个路径下载 SafariDriver.safariextz; 或者解压本地的selenium-server-standalone-2.48.0.jar,然后在org/openqa/selenium /safari里找到SafariDriver.safariextz;
Step 6:打开Safari -> Preferences -> Extensions (tab),然后将SafariDriver.safariextz拖进去就安装上了该extension了;
Step 7:在/Users/extrabux/library/safari/extensions下验证是否看到WebDriver.safariextz,看到就说明安装extension成功了;
Step 8:Java程序中,new一个SafariDriver之前加上下面这句,目的是不需要程序再自动安装SafariDriver extension了。
System.setProperty("webdriver.safari.noinstall", "true");
driver = new SafariDriver();