PDA

View Full Version : Applescript Safari how to click button




redwgaontoy
Jun 11, 2013, 09:20 PM
I am trying to write a script to make selections on a webpage in Safari.

So far my code is thistell application "Safari"
activate
do JavaScript "window.open('https://www.redwagontoy.com/miva/admin.mvc?Screen=MORD&Store_Code=RWTC')" in document 1
delay 3 -- need to allow enough time for the web page to load; adjust as necessary
end tell

tell application "System Events"
tell process "Safari"
repeat 3 times -- where x = the number of times it takes to reach the button using the tab key
keystroke tab
end repeat
delay 3
keystroke "P"

keystroke return -- performs the press action

tell application "Safari"
activate
do JavaScript "document.forms['search']['order_list_search_batch'].click()"

end tell
end tell
end tell



So this opens the webpage and tabs to the appropriate selection (attached Jpg of portion of screen) The it uses keystroke "P" to make a selection and then a return keystroke. Now I need it to select the "submit" button which I attempted to do, but did not work.

So how do I select the submit button.

I believe this is the source of the submit button
<input type="button" id="order_list_button_search" value="Search">

Once I figure out how to select the button, then I need to select the the top "checkbox" in the screenshot.png



redwgaontoy
Jun 11, 2013, 11:12 PM
I used the following code to click one of the buttons

tell application "Safari"

activate
tell document 1
do JavaScript "document.getElementById(\"order_list_button_neworder\").click()"
end tell


Now the other button is somewhat similar but has a drop down list next to it which I used keystroke down arrow to select the option. Now how do I click this button?

This is the source for that button

<!-- Status -->
<select id="order_list_search_status">
<option value="" selected>All Orders</option>
<option value="0">Pending</option>
<option value="100">Processing</option>
<option value="200">Shipped</option>
<option value="201">Partially Shipped</option>
<option value="300">Cancelled</option>
<option value="400">Backordered</option>
<option value="500">RMA Issued</option>
<option value="600">Returned</option>

So I need it to select Pending and then have it press the Search button.