Clicking a web link

Clicking a web link

Postby m2uk » Fri Jul 14, 2006 3:18 am

Hi there. I am presently evaluating this program and have came over an issue I cannot find the answer to in help or through google (or, of course, the keywords I am using are wrong).

I need to automate the clicking of a given web link (hyperlink) that is NOT presented as a "button" and the window position option is not working very well for me. However the TEXT remains constant for the hyperlink I would like to "press" in question.

Could someone kindly give me a pointer to this ? The automation I need would save me a lot of time (and eye strain, something when you have a visual problem you'd rather reduce) and it should work (I have got the program to switch to Safari and click buttons but not the hyperlinked option to progress

Thanks in advance !
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Fri Jul 14, 2006 10:20 am

give me the address of the page and what link you are trying to press and I might be able to come up with an AppleScript step to do it.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Postby m2uk » Fri Jul 14, 2006 11:00 am

Thanks. It is behind a log in and in Finnish :) Would it help if I a) could send a .PDF of the file, b) send a HTML file of the page or c) tell you the words of the link in question or a combination of the above.

Do you know if this "ability" could come in the future in the program as well !

Many thanks to you in advance.
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Fri Jul 14, 2006 12:37 pm

I'll send you a private message on the forum with the e-mail address to send it to.

QuicKeys already has a AppleScript step under Create>Scripting>AppleScript that you would just paste the code that I write into it.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Postby m2uk » Fri Jul 14, 2006 12:43 pm

Thank you. I appreciate this and will send the reply very quickly.
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Fri Jul 14, 2006 3:31 pm

I think this should do it, I had some problems with the html you sent me because it was having a hard time contacting the site. I just made up a dummy page that had the elements that were needed to test it and it seemed to work. I used information from this page Link no longer available on Apple's site.

just paste in the text below into a QuicKeys AppleScript step:

Code: Select all
tell application "Safari"
       set theCount to do JavaScript "document.links.length" in document 1
       set theButtonName to "Huutokauppaa uudelleen"
   
       repeat with loopVariable from theCount - 1 to 0 by -1
              if ((do JavaScript ("document.links[" & loopVariable & "].text") in document 1) = theButtonName) then
                     set the URL of document 1 to (do JavaScript "document.links[" & loopVariable & "].href" in document 1)
                     exit repeat
              end if
       end repeat
end tell
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Postby m2uk » Sun Jul 16, 2006 10:50 am

Thank you very much. It worked. I won't pretend to be able to understand the AppleScript but... :)

May I impose further on your goodwill and wonder if you would look at my workflow to see if there is a more elegant solution (I've had to start putting in delays as I cannot see how to verify if a certain piece of text exists in a window after clicking).

For example, how could I say "don't process anything until the words "Kohteesi hyväksyttiin ja lisättiin Huuto.Netin listoille." appear on the newly opened web page ?

Thanks again ! d
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Sun Jul 16, 2006 3:59 pm

check out: Link no longer available.
it has details on how to create a step to wait until a web page has finished loading.

And your other question about the button not working in Safari:
in the button step click on the Button Details button then click the Options tab and try the Tell button to click itself radio button.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Postby m2uk » Mon Jul 17, 2006 4:56 am

THANKS ! The link for "wait" made everything else fall into place for the first version :)

I am not a programmer and I think I need to adjust my mindset around the features and their use, but it is going nicely so far.

Now to register ! Thank You !

Darren
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby m2uk » Tue Jul 18, 2006 1:16 am

Following up on this (and thanks again for the help so far) is there a function where one can first say "open a link" in a mail message (there would only be one) but the URL changes slightly after the http://www.domain.net/ part of things+

With QuicKeys I think I could then

1.Switch to Application (Mail)
2.Switch to a given mail folder
3.RUN the "open URL " link I refer to above.
4.RUN the existing QuicKey script I have cobbled together with your help.
5.Upon close, switch back to mail and DELETE the mail message in question. And then close the SAFARI TAB in question (I think that can be done.. hopefully!)
6. Ideally (and I don't know how to do this bit either eloquently) check if there are any other messages in the folder stated in 2 and if so go back to option 3 else close.

Any further tips would be welcomed :) I've tried reading the online documentation but I still have not got my head around the very powerful options !

hanks
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Tue Jul 18, 2006 11:38 am

I think on your step 3 you are going to just have to have the sequence stop with a Create>QuicKeys>Wait>Wait for User step that is set to wait for the click on the link (Click with main button). There doesn't seem to be any AppleScript commands in Mail to find and click on a link.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

No problem

Postby kerryd » Sun Jul 23, 2006 2:19 pm

I have no problem with using the click command relative to the window to activate a hyperlink. I've used this extensively throughout a variety of websites. The other approach you can take is tab to the hyperlink. Just count the number of tabs, enter them in QuicKeys, followed by a return and this will activate a hyperlink. For me, because I have so many websites automated, an AppleScript for each one would be impractical. So I use clicks. Only occasionally does it fail and usually I just have to reset the entry point.
kerryd
 

Postby m2uk » Sun Jul 23, 2006 10:34 pm

Thanks both. Sorry for the delay (computer migration problem yesterday) in replying.

I used the click relative to position option as a stop gap and hoped that there was something else but found nothing. Just concerned for I move the font size up to read some mails and often forget to put it back ! But even with small "programming annoyances" (of my own doing, no doubt) Q3 is still great and is saving me much time, for which I am thankful !

Best wishes ! D
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby m2uk » Thu Aug 17, 2006 10:16 pm

Hi again.: Reopening this as sometimes the click option is just not working (i think when new mail comes in and other unknown items..)

Looking more at AppleScript suggests that there might be a way around it. I have tried using GETURL which allegedly takes the mailto link and opens it up in the browser. I tried adding GETURL and it opens the page but then QuicKeys complains about a missing variable ?!?

I am NOT very experienced with AppleScript and the googling I have done hasn't yielded much that works.

(Assume there is an Apple Mail folder with 50 messages)

The steps I need to undertake are:

1. From Apple Mail select the message at the top of the view (each message is different and must be handled separately) (effectively "taking that asset")

2. Open the URL given in the message body of the message selected in step 1 (I have tried the Geturl statement but QuicKeys claims that I have not defined a variable (!) yet AppleScript Editor doesn't mention this.

3. I can do the bits in the middle with QuicKeys...

4. After the actions made with QuicKeys have been done, I need to delete the message defined in step 1 (and this is where the problem has been as it doesn't always grab the right message to delete, perhaps due to new messages appearing in the view. Each message will have in the subject line a predictable subject line and a unique reference number if that helps.

And then with QuicKeys I can loop back to the start.

So.. help :) Basically... thanks !
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Mon Aug 21, 2006 9:06 am

what is the AppleScript code that you have that isn't working in QuicKeys?
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Postby m2uk » Mon Aug 21, 2006 9:36 am

The AppleScript code you wrote works very nicely, thank you. It is just the "open a link" I tried to research GETURL that I couldn't get to work but I really don't know AppleScript pleus the "can I delete a message" without getting the wrong message open question.

Thanks.
m2uk
 
Posts: 23
Joined: Fri Jul 14, 2006 3:12 am

Postby gb2 » Mon Aug 21, 2006 10:06 am

the AppleScript code that I wrote was for Safari clicking a button - it can't be used at all within Mail which I think you are wanting to do now. The GetURL within Mail looks like it is for passing a person's e-mail address and Mail would then open a new blank message addressed to that person. I think I said in one of the earlier posts that I didn't see any AppleScript in Mail to open a link and you would have to pause and do the click manually. You might be able to copy the message text out and paste it into some other program that has AppleScript that would open links, but I don't know of any. You might also want to stop by MacScripter and post a message there about what you want to do within Mail.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Re: Clicking a web link

Postby techno » Mon Sep 12, 2016 11:22 pm

I finally figured out a way to do this.

A site has a top 100 music downloads. The site is in CSS and each button was also hidden within a button element that QK couldn't find. I couldn't figure out how to decipher.
I did figure out that if I "disabled styles" that it would change it all to plain text via Develop Menu in Safari (I set this viewable via Onyx).

The above step may not be necessary for your needs.

Before I detail it. The trick that's needed is pressing "CTRL-L" or this centers the highlighted text or current position on your screen.
Then your link will always center at the same position. In order to figure out the position I ran record and then executed the steps.
Before running it you need to select the text you want to find on the page. Then press CMD-E (use selection for find). Then put your cursor above the 1st link you want to start with.

///Press Record:
CMD-G (Find Next)
CTRL-L (Centers Screen on cursor position or highlighted text)
Click the cursor on your Link
-----wait for the download to start
CMD-G (Find Next) // delete this out of your record, just use it to know where to insert the Repeat End function
///Stop Record

You now have the co-ordinates for the click point

Go back and edit your Record.... removing out any pauses or shortening them.
For some reason QK adds in some extra type keystroke "^" functions, without the "L", I left them.

Add Repeat "X" times (100 in my case) and Repeat End functions.
Boom

So happy to figure this out!
techno
 
Posts: 1
Joined: Mon Sep 12, 2016 11:04 pm


Return to QKM General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron