2016-10-27 25 views
0

我有一個嵌入JavaScript的AppleScript,可以在Safari上正常工作,但不能在Chrome上使用。AppleScript中的JavaScript可以在Safari上使用,但不適用於Chrome

的Safari瀏覽器版本(非相關部分刪除):

tell application "Safari" 
    activate 
     do JavaScript "document.getElementsByName('files[]')[0].click();" in document 1 
    end tell 

的Chrome版本:

tell application "Google Chrome" 
    activate 

    tell window 1 to tell tab 1 

     execute javascript "document.getElementsByName('files[]')[0].click();" 

    end tell 

的Chrome版本返回蘋果ScriptEditor 「缺失值」。

我能得到其他JavaScript命令的工作,我可以得到

document.getElementsByName('files[]')[0].click(); 

document.getElementsByName("files[]")[0].click();" 
在Chrome控制檯

當上了正確的網頁(認爲它可能是與雙引號 - 仍然可以我想)。

這裏是有問題的元素:

<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> 

任何想法?我已經嘗試了這麼多迭代。

document.getElementsByClassName('btn fileinput-button')[0].children[1].click(); 

在控制檯中工作,但不在AppleScript中工作。好像AppleScript的怪事給我,但是......

新增信息:

我可以得到一個登錄頁面上的「點擊」,所以它不是一個網站範圍的問題...

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 

工作正常嵌入在AppleScript中。

謝謝。

回答

相關問題