0

I am trying to automate clicking Allow for camera and microphone access in Safari when prompted. I have a TestCafe automated test that runs on Safari and I encounter the following camera and mic permission dialogs once the test starts:

Safari camera permission dialog Safari mic permission dialog

I have Safari Mock Capture devices enabled and would like these mock devices to be active when the test is running.

Here is what I am seeing in the Accessibility Inspector when viewing different Safari browser elements: Safari application specific Safari window with the permission dialog permission dialog box Allow button on the dialog box

I tried to click the Allow button with JXA running in the Script Editor app with no luck:

// Activate Safari, so you will be able to click like a user
Application("Safari").activate()

// Access the Safari process of System Events
var SystemEvents = Application("System Events")
var Safari = SystemEvents.processes["Safari"]

// Call the click command
Safari.windows[1].sheet[0].buttons[0].click()

I get the following error in Script Editor when running the JXA:

app = Application("Safari")
    app.activate()

app = Application("System Events")
    app.click(app.processes.byName("Safari").windows.at(1).sheet.0.buttons.at(0))
        --> Error -1700: Can't convert types.
Result:
Error -1700: Can't convert types.

How can I write AppleScript or JXA that can successfully click on the Allow button for both Safari permissions dialogs?

Jenny
  • 11
  • 2

0 Answers0