AutoHotkey Community

It is currently May 26th, 2012, 11:32 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 17th, 2009, 2:39 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
I am using COM to click an element on a web page.

Currently, here is my code
Code:
#Include C:\Program Files\AutoHotkey\LIB\COM.ahk
COM_Init()
F1::
{
pwb:=iWeb_getwin("External Launch")
com_invoke(pwb,"document.all[8].contentwindow.document.all[15].contentwindow.document.all[img-665580-665580-3899355].click")
}
return


My problem is that the numbers "665580-665580" can frequently change while the number "3899355" remains static. Beacause the 1st numbers change the script will be unable to find the element. The script must "see" the number 3899355 but be unable to ignore the others. How can I write the script as to remedy this problem?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 2:44 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Is it the first element on the page with that sort of name/id? If so, you could ReExMatch based one the entire frame HTML to find the numbers.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 2:47 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
no it's not.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 2:52 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Flight4birds wrote:
no it's not.
Hmmm, well something like this might still work:
Code:
frame := COM_Invoke(pwb, "document.all[8].contentwindow.document.all[15].contentwindow")
HTML := COM_Invoke(frame, "document.documentElement.innerHTML") ; get frame HTML
RegExMatch(HTML,"img-\d+-\d+-3899355",id)
COM_Invoke(frame,"document.all[" id "].click")
COM_Release(frame)

Otherwise, I would try to find another way to identify the element (value, innerText, innerHTML, href).


Also, I would recommend releasing all COM objects and Terminating COM if you post a fully functional script :wink: .
Code:
COM_Init()
F1::
{
pwb:=iWeb_getwin("External Launch")
com_invoke(pwb,"document.all[8].contentwindow.document.all[15].contentwindow.document.all[img-665580-665580-3899355].click")
COM_Release(pwb), COM_Term()
}
return

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 3:32 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
jethrow said
Quote:
Otherwise, I would try to find another way to identify the element (value, innerText, innerHTML, href).


Can we try the innertext route?
Using tank's iwebbrowser2 window spy I get
Code:
MX55/29 Nov

as the inner text of the element.
What's the code to click this element?
Also, because of the quirkiness of this web page, can we implement the code I used at the top? It's the only way I've gotten COM to work on this web page. thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 4:28 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Try this (note - the javascript is case-sensitive):
Code:
#Include C:\Program Files\AutoHotkey\LIB\COM.ahk
COM_Init()
innerText := "MX55/29 Nov"

F1::
   pwb:=iWeb_getwin("External Launch")
   code := "javascript: all=document.all[8].contentWindow.document.all[15].contentWindow.document.all; for(i=0;i<all.length;i++){if(all[i].innerText=='" innerText "'){break}}; void 0"
   COM_Invoke(pwb, "Navigate", code)
   index := COM_Invoke(pwb, "document.parentWindow.i")
   COM_Invoke(pwb,"document.all[8].contentwindow.document.all[15].contentwindow.document.all[" index "].click")
   COM_Release(pwb), COM_Term()
Return


Note - I believe the updated iWeb function library that tank & sinkfaze are working on should be able to recurse into frames and click on an element by innerText:
tank wrote:
Code:
F1::
COM_Init()
   pwb:=iWeb_getwin("External Launch")
   iWeb_clickText(pwb,"MX55/29 Nov","8,15")
   COM_Release(pwb), COM_Term()
Return

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:01 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
Hahahaaaa! I love AHK! works like a charm, thanks Jethrow! :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:03 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Flight4birds wrote:
... works like a charm ...

Which one? I know tank's is much shorter/simpler, but do both examples work?

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:16 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
whoops sorry. I got the first one to work, the second code has an error message at line 4 saying that there are too many parameters passed to that function.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2009, 5:24 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
You need to download the updated iWeb Standard Library.

Note - I'm pretty sure tank will be changing it, but currently the top part of the library (above iWeb_Init()) needs to be commented-out.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 1:40 am 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
I updated the new iWeb Standard Library but when I run the code
Code:
F1::
COM_Init()
   pwb:=iWeb_getwin("External Launch")
   iWeb_clickText(pwb,"MX55/29 Nov","8,15")
   COM_Release(pwb), COM_Term()
Return


nothing happens, no error message or anything.

I have another question though about the code that is working here
Code:
#Include C:\Program Files\AutoHotkey\LIB\COM.ahk
COM_Init()
innerText := "MX55/29 Nov"

F1::
   pwb:=iWeb_getwin("External Launch")
   code := "javascript: all=document.all[8].contentWindow.document.all[15].contentWindow.document.all; for(i=0;i<all.length;i++){if(all[i].innerText=='" innerText "'){break}}; void 0"
   COM_Invoke(pwb, "Navigate", code)
   index := COM_Invoke(pwb, "document.parentWindow.i")
   COM_Invoke(pwb,"document.all[8].contentwindow.document.all[15].contentwindow.document.all[" index "].click")
   COM_Release(pwb), COM_Term()
Return

When the text does exist, the code works as it should and clicks the text. When the text is not there I get an error message about click not being a proper dispatch object. What I'd like to do is eventually run an loop script so that when the text "MX55/29 Nov" does exist, it is clicked.But with the error message popping up ever time it doesn't find the text, this is problematic. Any thoughts or pointers?

Also, is it possible, using this script to search for a whole set of text? For ex. if any of the text appears (MX55/29 Nov, FD42/28 Nov, GW88/26 Nov" it will click whichever one comes appears first.
Thanks for the help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 7:23 pm 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
ping


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 8:05 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
does the text exist when nothing happens?


the second one gives you an error because it attempts to click an element that doesnt exist

the iweb function just does nothing if the text isnt found

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2009, 8:14 pm 
Offline

Joined: March 6th, 2008, 11:54 pm
Posts: 167
Yes, the text exist when nothing happens with the 1st code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2009, 2:00 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
and this text(MX55/29 Nov) appears nested somewhere inside an A tag?

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Leef_me, Maestr0, Pulover, rbrtryn and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group