why doesn't 'do javascript' call in Applescript execute when the same code typed into browser does?

后端 未结 1 1745
栀梦
栀梦 2021-01-05 08:45

I\'m trying to figure out why my Applescript does nothing when the same javascript code typed into a Safari location bar works.

Go to a search results page, such as:

相关标签:
1条回答
  • 2021-01-05 09:00

    The problem is that do JavaScript has to correctly address a tab in a Safari window.

    The following script works for me, if the search results page is the current tab in the frontmost Safari window:

    tell application "Safari"
        activate
        set theScript to "document.getElementsByClassName('vspib')[0].click();"
        do JavaScript theScript in current tab of first window
    end tell
    
    0 讨论(0)
提交回复
热议问题