AppleScript JavaScript getElements

applescriptgoogle-chromejavascript

I have my script partially working. I'm using AppleScript to script interactions with Chrome.

set textToSave to "Text"

tell application "Google Chrome"
    execute front window's tab 1 javascript "document.getElementsByName('0.9.7.1.5.0.4.1.3')[0].click();"
    delay 0.1
  1. If I enter a multiple line textToSave for example

    " here
    blabla 
    
    bla"
    

    then I have no text and –> missing value

  2. I need to set a popup field before this script, here is the HTML for it

    <select id="PaymentEnSelection" name="0.9.7.1.5.9.4.1.9"> <option selected="selected" value="0">Enabled</option> <option value="1">Disabled</option></select>
    

    and a another one :

    <select name="0.9.7.1.9.0.4.1.9.0.2.1.3.7.3.9.3.1"><option value="NoSelectionString">Please select a reason</option>
    <option value="0">R1</option>
    <option value="1">&amp; Review </option>
    <option value="2">Chart</option>
    <option value="3">R3</option>
    

Best Answer

Multiline text can be achieved using either of the following methods:

  • Separate the text by new lines, with the first quote and last quote encapsulating the contents.

  • Use \n as new line.

    set myvar to "hello\nanother\n\nfinal"
    

You can set the value of a select element using the following JavaScript

document.getElementById("PaymentEnSelection").value = 1

The value given is one of the value attributes on the option elements that you wish to select.