admin管理员组

文章数量:1406308

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

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

Share Improve this question asked Dec 16, 2010 at 18:35 piercelaynepiercelayne 531 silver badge4 bronze badges 1
  • I don't know how to do Javascript from Applescript, but the form has a method named submit() that will send it. Is that what you're looking for? – Pekka Commented Dec 16, 2010 at 18:47
Add a ment  | 

1 Answer 1

Reset to default 4

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

http://www.libertypages./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('pleteShip.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('pleteShip.ship.field').click()" in doc
end tell

本文标签: Using javascript with applescript to submit data on a webpageStack Overflow