How to click specific text on webpage when text shows multiple times?

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 <a onclick="editProdcut('7383367')"> 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?


User uploaded file


Thanks so much,

Lorne

MacBook Pro, Mac OS X (10.7.2)

Posted on Aug 22, 2012 6:48 AM

Reply
3 replies

Aug 22, 2012 7:07 AM in response to Lorne17

I found this script:

[applescript]tell application "Safari"

open location "http://google.com"

delay 1

do JavaScript "document.forms[0]['btnI'].click()" in front document

end tell[/applescript]



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

[applescript]<font class="buttonBasicText">[/applescript]



So since I have 31 products on this page, I have 31 font tags with the same class. Also, the webpage will always be different, so rather than telling it to go to a specific URL, I just want to tell AS to go to the active page in Safari.


Thoughts?

Thanks,

Lorne

Aug 22, 2012 12:02 PM in response to Lorne17

Ok I thought this might help. 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, <a> tag, or <font> 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

clickat {330, 825} -- {from left, from top}

delay 1

keystroketab

keystroketab

keystroketab

keystroketab

keystroke "4.50"

key code 121 -- {page down to reveal save button}

delay 1

clickat {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

clickat {345, 424} -- {from left, from top}

delay 1

keystroketab

keystroketab

keystroketab

keystroketab

keystroke "3.60"

delay 0.5

clickat {345, 464} -- {from left, from top}

-- {END Kids T-shirt SAVED}


end tell



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

Lorne

Aug 22, 2012 12:17 PM in response to Lorne17

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


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>


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to click specific text on webpage when text shows multiple times?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.