On Mac OS 10.12/Safari 10.1, Safari loses focus to GridLauncher, which is the Selenium server process, and Selenium commands fail with:
00:45:24.395 WARN - Exception thrown org.openqa.selenium.NoSuchWindowException: The driver is not focused on a window. You must switch to a window before proceeding. (WARNING: The server did not provide any stacktrace information)
Similarly, on Mac OS 10.12/Safari 11.0, Safari loses focus to GridLauncherV3 (V3 because Safari 11 is using Selenium 3 by default). This is causing issues such as being unable to find an element when Safari is not in focus:
22:11:23.315 INFO - Executing: [find element: By.xpath: (//div[contains(@class, 'Select-option')])[position()=7]]) 22:11:23.399 WARN - Exception thrown org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
This is an Apple bug, not a Sauce Labs bug. It was reported to Apple in the bug report at http://www.openradar.me/radar?id=4982823136002048, which was closed as a duplicate of another bug. The problem has been addressed in the Safari Technology Preview, so when Apple releases Safari 11.1 as part of an OS update, this issue should be resolved on Sauce Labs.