Applescript Safari how to click button

Discussion in 'Mac Programming' started by redwgaontoy, Jun 11, 2013.

  1. redwgaontoy macrumors newbie

    Jun 10, 2013
    I am trying to write a script to make selections on a webpage in Safari.

    So far my code is this
    tell application "Safari"
    	do JavaScript "'')" 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"
    			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

    Attached Files:

  2. redwgaontoy thread starter macrumors newbie

    Jun 10, 2013
    Now I can get it to click some buttons but not search

    I used the following code to click one of the buttons

    tell application "Safari"
    			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.

Share This Page