Applescript | Javascript - Click on Link using Javascript?

徘徊边缘 提交于 2019-12-07 18:31:25

I'm not sure if this is the answer you're looking for but you can get the value of the href attribute of the anchor tag by getting childNodes. The value returned by JavaScript is the URL you want to set your document eventually. Instead of using a click I get the desired location and set the URL of document 1 to it; the result/goal will be the same as a click.

tell application "Safari"
    tell document 1
        set URL of it to do JavaScript "document.getElementById('date-of-last-upload').childNodes[1].href"
    end tell
end tell

EDIT: to open the url in a new tab (if opening links in tab is set to automatic in preferences) you can change the set URL of it to into open location

tell application "Safari"
    tell document 1
        open location (do JavaScript "document.getElementById('date-of-last-upload').childNodes[1].href")
    end tell
end tell 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!