How to click specific text/button on website when there's multiple

Hello there,

I am trying to setup a script to help me to click multiple places on a page, enter the price of my product, then save changes. However each product I have lots of different items, so the text “Edit Product Info” is on the page multiple times. The HTML code puts the active button in Unfortunately each product has a different number there, so I can’t tell it to go to that link. Is there a way to tell AS to press “Edit Product Info” then change price, and save?

Thanks so much,
Lorne

Model: MacBook Pro
Browser: Safari 537.1
Operating System: Mac OS X (10.7)

I found this script:

tell application "Safari"
  open location "http://google.com"
  delay 1
  do JavaScript "document.forms[0]['btnI'].click()" in front document
end tell

But that’s obviously for google. However my buttons since I have multiple of them, are titled the same id in this code:

<font class="buttonBasicText">

So since I have 31 products on this page, I have 31 font tags with the same class.

Thoughts?
Thanks,
Lorne

Sorry to keep posting, but I figured I’ll keep you up to speed.

This is what my current script is. I had it working a couple months back. But the website button location must have changed so now my coordinates are not accurate.

Basically I need to get rid of the exact coordinates and tell the mouse to click directly on the link, tag, or tag.

Applescript Code:

 
-- {Things to check before running.]
-- {No tabs are open]
-- [Description is just one line}
 
tell application "Safari" to set the bounds of the front window to {0, 0, 1440, 900}
 
tell application "Safari"
activate
end tell
 
tell application "System Events" to tell process "Safari"
 
-- {Kids Organic T EDIT}
key code 115 -- {page home to scroll all the way up}
delay 1
click at {330, 825} -- {from left, from top}
delay 1
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke "4.50"
key code 121 -- {page down to reveal save button}
delay 1
click at {345, 127} -- {from left, from top}
-- {END Kids Organic T SAVED}
 
-- {Kids T-shirt EDIT}
delay 1
key code 115 -- {page home to scroll all the way up}
delay 1
key code 121 -- {page down to reveal edit button}
delay 1
click at {345, 424} -- {from left, from top}
delay 1
keystroke tab
keystroke tab
keystroke tab
keystroke tab
keystroke "3.60"
          delay 0.5
click at {345, 464} -- {from left, from top}
-- {END Kids T-shirt SAVED}
 
end tell

Now I tried this code (basic and dumbed down so that I can test it). But it doesn’t work. Doesn’t give me an error either.

AppleScript Code:

tell application "Safari"
          set theName to do JavaScript "document.getElementByClassName('buttonBasicText').click();" in document 1
end tell

The HTML on the page for the buttons (multiple instances of same “Edit Product Info”) is:

HTML Code:

<td>
 
<div id="all_button_7383366" name="all_button_7383366" style="display: block; ">
 
 
<table cellpadding="0" style="border-collapse: collapse; ">
 
 
<tbody>
 
 
<tr>
 
 
<td width="117" nowrap="">
 
 
<table cellpadding="0" style="border-collapse: collapse;">
 
 
<tbody>
 
 
<tr style="line-height: 14px;">
 
 
<td class="buttonBasic">
 
 
<a onclick="editProduct('7383366')" style="text-decoration: none; cursor: pointer;">
 
 
<img src="http://www.printfection.com/skin1/images/buttons/button_basic_left.gif" border="0" align="top" style="vertical-align: top;"/>
 
<font class="buttonBasicText">Edit Product Info</font>
<img src="http://www.printfection.com/skin1/images/buttons/button_basic_right.gif" border="0" align="top" style="vertical-align: top;"/>
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<div id="all_button_7383366_edit" name="all_button_7383366_edit" style="display: none; ">
</td>

Can anyone help with some input? I cannot figure this out for the life of me!
Lorne

Model: MacBook Pro
AppleScript: 2.4.3
Browser: Safari 6.0
Operating System: Mac OS X (10.7)

Hi,

sorry, parsing websites depends strongly on the source code and scripting is a lot of trial & error
so it’s pretty hard to help in this case.

I’m wondering, if the site contains your products that implies you own the site,
you have access to the database (probably a mysql database).
Then a php script might be the better solution to change the values directly in the database.

Hello Stefan,

Thanks for the reply. Unfortunately no I do not own the site. These products are posted in my suppliers site. I.E. T-shirt printer’s site. I just post my products and the commisions, then link to that product and people checkout through my printer.

Make sense?

Is there any information I can try to provide to get help, cuz I don’t know AppleScript really at all so I don’t know where to start on this one.

Thanks,
Lorne