Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using javascript with applescript to submit data on a webpage

I am trying to log into a website using javascript (do javascript) in an applescript I am writing. I have been able to parse data using (document.getElementById) but I can't find anything to be able to send data in order to input data to the webpage and or to log in.

The elements I am working with are:

<input style="width:80%;" type="text" name="ssn" id="ssn">

<input type="password" name="password" style="width:80%;">

<input type="radio" value="current" name="period" checked="checked">

<input type="submit" value="Submit" name="Action">

First bit is my username, the next my password, after that a radio button that is for selecting my log in type and then the submit button.

If there is anyway to do this any help would be greatly appreciated.

Thanks

like image 333
piercelayne Avatar asked Dec 02 '25 05:12

piercelayne


1 Answers

I have an example of filling in forms at FedEx at my blog.

http://www.libertypages.com/clarktech/?page_id=1570

In that script I don't submit the form (since I normally want to check over the submission first). I recently modified it to auto-submit although I've not written up that script yet. However the addition is simple. At FedEx you just do the following. (You can add this to the script linked to above)

Safari.do_JavaScript(u"document.getElementById('completeShip.ship.field').click()", in_=FEdoc)

This gets the submission button by ID and then clicks it. You should be able to easily modify this to your script if the website utilizes IDs.

Note that all the above uses Appscript and Python. (My favorite scripting environment) To do this in pure Applescript you just change the above to something like

tell application "Safari"
  activate
  weight = "2"
  set doc to document "FedEx | Ship Manager | Shipping"
  do JavaScript "document.forms['shipActionForm']['psd.mps.row.weight.0'].value = '" & weight & "'" in doc
  do JavaScript "document.getElementById('completeShip.ship.field').click()" in doc
end tell
like image 59
Clark Avatar answered Dec 03 '25 18:12

Clark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!