3

I Would like to perform tests in safari, using selenium.

Unfortunately, when I try to debug issues using the safari, a notification appears which requires me either disable automation in safari or to quit (attached image).

why I cannot do it as in Chrome & FireFox (for ex: press F12 to see the DOM) ? error screenshot

Note: I'm using MacOs Catalina with Javascript & Python for selenium

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

4 Answers4

1

This error message...

Safari window

...implies that the Safari browser's WebDriver support for developers and automation developers is turned off by default.


Configure Safari to Enable WebDriver Support

As per the documentation in Testing with WebDriver in Safari Safari's WebDriver support for developers is turned off by default. Enabling the WebDriver support depends on your operating system.

  • In High Sierra and later:

    • You need to enable safaridriver once.

      /usr/bin/safaridriver --enable
      
    • If you’re upgrading from a previous macOS release, you may need to use sudo as follows:

      sudo /usr/bin/safaridriver --enable 
      
  • Sierra and earlier:

    1. To make the Develop menu available. Choose Safari > Preferences and on the Advanced tab, select Show Develop menu in menu bar.
    2. Choose Develop > Allow Remote Automation.
    3. Authorize safaridriver to launch the XPC service that hosts the local web server. To permit this, manually run /usr/bin/safaridriver once and follow the authentication prompt.
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • 1
    unfortunately, I already did it. the automation runs fine, but whenever I click the browser, this popup appears, and doesnt allow me to use manual debugging within the automation instance – Danny Kaminski Jun 08 '20 at 08:08
0

This should solve your problem.

warnFromSafari = driver.SwitchTo().Alert();

warnFromSafari.Accept();
0

So, to summarize for all other (frustrated) developers who come across #Safari and try to automate it.. it is impossible to write automation because of this limitation.

So the options are:

  1. Write in other browser (such as chrome) and verify it works in safari
  2. Manually in other session in safari(manual) locate your locators/paths and then insert to you automation-infra

and to add to complexity - Selenium clicks doesnt work in many places where on chrome/ff/edge DO work. so, possible solution to that - is to use JS in DOM - but that is also not perfect.

hopefully the situation will improve

-1

Unfortunately we don't seem to be able to pause the tests, interact with the browser and then resume the tests afterwards with safaridriver, as we can with geckodriver and chrome webdriver. The closest option you have is to 'Stop Session' in the pop-up from your screenshot.

From what I can see the 3 options listed are:

Turn off all automation - Stops the test and turns off all the automation settings. This will require you to allow remote automation/enable safaridriver again.

Stop session - this stops the test but leaves the browser open so that you can manually interact with it and use the Web Inspector tools.

Continue session - this closes the pop-up and continues with the test.

  • If you had read through the other answers instead of rewriting the question as an answer, you might know that it is possible to turn off the error message. If you consider editing your answer, I will consider removing the downvote. Be sure to [write a good answer](https://stackoverflow.com/help/how-to-answer). – myjobistobehappy Nov 27 '20 at 22:35
  • @myjobistobehappy - the original question relates to the ability to manually intervene and use the inspector features whilst running the test in debug mode - "why I cannot do it as in Chrome & FireFox (for ex: press F12 to see the DOM) ?" I am the only person who has answered that - and from what I can see I'm the only person who has read the question that was asked, yourself included. – cmcintyre Nov 29 '20 at 23:30
  • the question being asked is how to avoid that message. "Unfortunately, when I try to debug issues using the safari, a notification appears which requires me either disable automation in safari or to quit". The question then asks, "why I cannot do it as in Chrome & FireFox". This means, why doesn't selenium perform the way as it performs with Chrome and Firefox on MacOS. ***I understand the words can be tricky ;)*** – myjobistobehappy Nov 30 '20 at 07:29
  • i still couldn find a solution to it. the only conclusion i got, that apple and safari are NOT friendly for automation. hence, we dropped the support for safari. – Danny Kaminski Nov 30 '20 at 09:40