Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start safari with extension using safariDriver in selenium

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?

like image 507
mosaad Avatar asked May 22 '17 14:05

mosaad


People also ask

How do I launch Safari using Selenium?

How do I automate Safari browser using Selenium? Step 1: Download and Install the Safari Browser Extension. Step 2: Enable the WebDriver Browser Extension by going to Safari > Preferences and open the preferences window and then enable the “Enable WebDriver“ option. Step 3: Restart your Browser.

How do I automate Safari browser?

Choose Safari > Preferences, and on the Advanced tab, select “Show Develop menu in menu bar.” For details, see Safari Help. Choose Develop > Allow Remote Automation.

Can I use Selenium with Safari?

Yes Selenium webdriver supports Safari browser. Safari is a prominent browser and is provided by default by Apple devices. For Safari versions 10 and greater than 10, the safaridriver comes automatically and is not required to be installed separately. The location of the SafariDriver is: /usr/bin/safaridriver.


1 Answers

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
like image 119
jakob Avatar answered Jan 18 '23 17:01

jakob