Skip to content Skip to sidebar Skip to footer

Using Javascript | Applescript To Click Button In Safari

I realize there are several threads about this and they are all very specific to certain website . My background is in Python, not Javascript or Applescript, and I'm confused on ex

Solution 1:

Change your JavaScript query from

document.forms['search']['order_list_search_batch'].click()

to

document.forms['form']['proceed'].click()

If you inspect the proceed button, you'll find that it's inside a form element with a "name" attribute with the value "form". The button itself has a "name" attribute with the value "proceed". So in your JavaScript, the first term between brackets looks for the form named "form" and the second one refers to the element named "proceed" inside the "form"-form. If that makes any sense ;-)

Also, you will have to tell AppleScript in which document to execute the JavaScript. The document you just opened will probably be document 1, if there are no other tabs open.

Hope this helps!

The entire code:

tell application "Safari"
activate
open location "http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"
delay 3do JavaScript "document.forms['form']['proceed'].click()" in document 1
end tell

Solution 2:

You could use the javascript dom function getElementsByName(), it will return an array of all elements with that name and you can (in this case) target the first item.

Also you will need to specifically target the tab you want to execute the javascript in to get it working in Safari.

See below

tell application "Safari"
    activate
    open location "http://rna.tbi.univie.ac.at/cgi-bin/RNAfold.cgi"
    delay 3
    do JavaScript "document.getElementsByName('proceed')[0].click();" incurrent tab offirstwindowend tell

Post a Comment for "Using Javascript | Applescript To Click Button In Safari"