kluznic

Q: Applescript do javascript submit in safari

Hi,

 

I have a script that is supposed to do a bunch of stuffs on safari like ticking radio boxes and all, saving then submitting.

 

However, upon clicking the submit button - manually / with script, there'll be a pop up window with options " OK or Cancel ".

 

tell application "Safari"

-- this triggers the pop up window

do JavaScript ("document.getElementById('submitButton').click()") in document 1

 

-- trying to click the ok button using whatever knowledge I know

tell application "System Events" to key code 36

tell application "System Events" to tell process "Safari"

     if exists (button "OK" of window 1) then

          click (button "OK" of window 1)

     end if

end tell

 

I think the main problem is the script "waits" at the do Javascript line for a response of an OK or cancel before it continues running the rest of the script like hitting enter or clicking the OK/ cancel. It is not a new window, and the pop up window cannot be dragged/moved.

Is there a way to solve this?

OS X El Capitan (10.11.4), null

Posted on Jun 28, 2016 1:17 AM

Close

Q: Applescript do javascript submit in safari

  • All replies
  • Helpful answers

  • by kluznic,

    kluznic kluznic Jun 28, 2016 1:39 AM in response to kluznic
    Level 1 (8 points)
    Mac OS X
    Jun 28, 2016 1:39 AM in response to kluznic

    Screen Shot 2016-06-28 at 4.37.56 PM.png

    The pop up looks like this that appears right in the middle of my safari page, undraggable and cannot inspect element.

  • by Camelot,Solvedanswer

    Camelot Camelot Jun 29, 2016 1:02 AM in response to kluznic
    Level 8 (47,285 points)
    Mac OS X
    Jun 29, 2016 1:02 AM in response to kluznic

    That doesn't look like a standard system UI dialog... it's a HTML element.

     

    As such you should be able to examine the source of the page and find the HTML element that corresponds to the OK button and effect a 'click' to dismiss the dialog and submit the form.

  • by kluznic,

    kluznic kluznic Jun 28, 2016 8:02 PM in response to Camelot
    Level 1 (8 points)
    Mac OS X
    Jun 28, 2016 8:02 PM in response to Camelot

    Well.. the first submit button that the script clicks using "do JavaScript ("document.getElementById('submitButton').click()") in document 1" has an onclick javascript function attached to it.

     

    function submitforsettlement() {

          var submitOK = confirm("By submitting this sales voucher for settlement, you confirm that the customer has received their goods and \nyou have kept a signed copy of the sales voucher.");

          if (submitOK) {

         // does the success path of submitting

          }
    }

     

    How do I toggle that submitOK var to true in "do JavaScript ("document.getElementById('submitButton').click()") in document 1"?