13

I want to start my browser with my extensions. In chrome I can use the chromeOptions as in code sample below. Firefox works in a similar way.

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));

However in Safari there is no addExtensions method. What is the correct way to do this with Safari?

mosaad
  • 1,893
  • 4
  • 20
  • 46
  • I found this from 2 years ago but it does not work anymore https://stackoverflow.com/questions/15005833/browser-plugin-testing-with-selenium – mosaad May 23 '17 at 09:33
  • May I know which version of Safari are you using? – iamkenos May 30 '17 at 05:33
  • It should not matter but 9 or 10 – mosaad May 30 '17 at 08:44
  • It will. I was willing to try it out myself but seems apple stopped releasing safari for windows. Latest I got was 5.1.7 which had a different implementation of safaridriver. Possibly the one on the link you gave. – iamkenos May 30 '17 at 09:17

4 Answers4

1

This might help. https://github.com/SeleniumHQ/selenium/wiki/SafariDriver

I found that if you want to open another safari extension inside safari, you have to do it from the safari browser itself. https://github.com/SeleniumHQ/selenium/wiki/SafariDriver-Internals#building-the-safaridriver

So basically:

  1. Sign up for Apple's (free) Safari Developer Program and generate a signed certificate for the extension.
  2. Build the SafariDriver extension: $ ./go safari
  3. Install the extension:
  4. Launch Safari
  5. Enable the Develop menu (Preferences > Advanced > Show Develop menu in menu bar)
  6. Open the Extension Builder (Develop > Show Extension Builder)
  7. Add a new extension: $SELENIUM_CLIENT/build/javascript/safari-driver/SafariDriver.safariextension
  8. Click Install
jakob
  • 35
  • 7
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Alessandro Cuttin Aug 16 '17 at 15:26
  • 1
    Thanks for the feedback I have changed the answer, to be more likable hopefully. – jakob Aug 16 '17 at 20:48
0

Which version of Selenium are you using? It looks like they added safariOptions.addExtensions(".."); in June of 2013.

SafariOptions options = new SafariOptions();
options.addExtensions(new File("path/to/extension.safariextz"));
WebDriver driver = new SafariDriver(options);
0

The Apple-maintained safaridriver implementation does not support configuring extensions via WebDriver capabilities or other automated means. If you feel that this is an important feature worth doing, please file an enhancement request at https://bugreport.apple.com/ with more details of your use case.

Brian Burg
  • 679
  • 4
  • 10
-2

SafariDriver is a class in the org.openqa.selenium.safari package is used to access safari browser

WebDriver driver = new SafariDriver();
driver.get("https://stackoverflow.com");
iamsankalp89
  • 4,242
  • 2
  • 12
  • 35