I have a little AppleScript with embedded Javascript that works fine on Safari, but not on Chrome.
The Safari version(non relevant portions deleted):
tell application "Safari"
activate
do JavaScript "document.getElementsByName('files[]')[0].click();" in document 1
end tell
The Chrome version:
tell application "Google Chrome"
activate
tell window 1 to tell tab 1
execute javascript "document.getElementsByName('files[]')[0].click();"
end tell
The chrome version returns "missing value" in Apple ScriptEditor.
I CAN get other javascript commands to work and I can get
document.getElementsByName('files[]')[0].click();
or
document.getElementsByName("files[]")[0].click();"
in the Chrome console when on the proper webpage (thought it may have something to do with double quotes - still could be I suppose).
Here is the element in question:
<h3>Add new documents for this patient
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn fileinput-button" style="float: right !important;">
<span>Select Files to Upload</span>
<input type="file" name="files[]" multiple="">
</span>
</h3>
Any ideas? I have tried so many iterations of this.
document.getElementsByClassName('btn fileinput-button')[0].children[1].click();
works in the console, but not when in AppleScript. Seems like AppleScript weirdness to me, but...
Added information:
I can get a "click" on the logon page, so it isn't a site wide issue...
tell window 1 to tell tab 1
execute javascript "document.getElementById('username').value='someLoser';"
execute javascript "document.getElementById('password').value='YouWish'"
execute javascript "document.getElementsByClassName('btn btn-md btn-primary')[0].click();"
end tell
works fine embedded in AppleScript.
Thanks.