AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

need help automating a few clicks on a website
Goto page 1, 2, 3, 4, 5  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
marcusjb
Guest





PostPosted: Wed Jun 24, 2009 7:48 am    Post subject: need help automating a few clicks on a website Reply with quote

I'm trying to write a script to do this:

sample page code here: http://pastebin.com/mc4473d8

1. Auto-refresh the page about once per second.

2. sometimes when the page is refreshed the yes no boxes will appear, i need to recognize the yes box and click it, then click ok on the dialog box that pops up to confirm.

3. then the it would go back to refreshing itself and after successfully completing this 4 or 5 times, I'd like the script to kill itself. (Generally this will take approximately 1 hour to complete this 5 times)

Thank you in advance for your help
Back to top
deleyd



Joined: 08 Mar 2008
Posts: 64
Location: Santa Barbara

PostPosted: Wed Jun 24, 2009 6:26 pm    Post subject: Reply with quote

The following may help:

Example of Navigating a Website
http://www.autohotkey.com/forum/viewtopic.php?t=42488

If a yes/no dialog box comes up, is there a window title for that dialog box? You could check to see if a window with that title exists, and if so then deal with it. (Rather than trying to click yes/no, there may be a keyboard shortcut that's easier. Possibly ctrl-Y or ctrl-N.)

Keep a counter and when the counter reaches 5 you can end the script.
Back to top
View user's profile Send private message Visit poster's website
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Wed Jun 24, 2009 11:48 pm    Post subject: Reply with quote

Quote:
sample page code here: http://pastebin.com/mc4473d8

Is that the actual website? Or could you provide a link to the website?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
AtWork
Guest





PostPosted: Fri Jun 26, 2009 10:56 am    Post subject: Reply with quote

You can use this Firefox addon: https://addons.mozilla.org/en-US/firefox/addon/3863
Back to top
AtWork
Guest





PostPosted: Fri Jun 26, 2009 10:59 am    Post subject: Reply with quote

forgot to mention:

For page refreshes, use http://wiki.imacros.net/REFRESH

For clicking the browser dialogs, use http://wiki.imacros.net/ONDIALOG (should be added automatically during recording)
Back to top
marcusjb



Joined: 24 Jun 2009
Posts: 35

PostPosted: Sat Jun 27, 2009 6:12 am    Post subject: Reply with quote

I can't provide the actual page because its an internal company site.

Thanks for your replies. Hopefully i can figure this stuff out.
Back to top
View user's profile Send private message
marcusjb



Joined: 24 Jun 2009
Posts: 35

PostPosted: Sat Jun 27, 2009 6:29 am    Post subject: Reply with quote

How can I have it refresh the page until this appears "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1" ?
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Sat Jun 27, 2009 6:39 am    Post subject: Reply with quote

Are you using IE? If so, this might help with step 1:
Code:
COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   sleep 2000
   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
;   if . . .  check for dialog boxes
}

Note - Sean's GetWebBrowser() function can be found at http://www.autohotkey.com/forum/topic24930.html (2nd from bottom)
In this example, the IE webpage needs to be the active window for GetWebBrowser() to work.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Sat Jun 27, 2009 7:14 am    Post subject: Reply with quote

Quote:
How can I have it refresh the page until this appears "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1" ?

Code:
COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
   IEReady()
   if % COM_Invoke(pwd, "document.getElementById[ctl00_cph_content_dgOrders_ctl03_rbl_1]")
      break
}

You want to make sure the page is loaded before testing for "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1". Check out this topic: http://www.autohotkey.com/forum/viewtopic.php?t=19256. I used Sean's IEReady() function (which is found in the first post). It doesn't work with every webpage, but there are other examples in that thread too.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
marcusjb



Joined: 24 Jun 2009
Posts: 35

PostPosted: Sat Jun 27, 2009 8:07 am    Post subject: Reply with quote

yeah so, this is apparently all over my head.

i've got the COM.ahk, now what am i supposed to do with this GetWebBrowser function, does it need to be a separate file?
Back to top
View user's profile Send private message
Jayman



Joined: 21 Oct 2007
Posts: 54

PostPosted: Sat Jun 27, 2009 8:58 am    Post subject: Reply with quote

The COM.ahk belongs in your program files\autohotkey\lib folder.

Any script you right now can make use of the pre-scripted library of functions.
Back to top
View user's profile Send private message
marcusjb



Joined: 24 Jun 2009
Posts: 35

PostPosted: Sun Jun 28, 2009 8:39 pm    Post subject: Reply with quote

This is the first time I've worked with AHK, and i'm pretty lost.

This is what i've got so far
Code:
Run file:///C:\code.html

COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
   IEReady()
   if % COM_Invoke(pwd, "document.getElementById[ctl00_cph_content_dgOrders_ctl03_rbl_1]")
      break
}



GetWebBrowser()
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   If Not   hIESvr
      Return
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2,

"Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0,

"UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2,

"Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0,

"UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


and obviously, it doesn't work.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Mon Jun 29, 2009 4:20 am    Post subject: Reply with quote

Quote:
yeah so, this is apparently all over my head.

Quote:
This is the first time I've worked with AHK, and i'm pretty lost.

That's quite alright. Very Happy According to the Wiki, these are Advanced topoics - http://www.autohotkey.com/wiki/index.php?title=Tutorials
You may want to check out "COM Tutorial by tank" & "Control/manipulate webpages using JavaScript by daonlyfreez"
Note - Tank's tutorial was written before the "Dot Syntax" was incorporated into the COM.ahk Library. Example:
Code:
COM_Invoke(pwd, "document.getElementById[Passwd]")
;would have been written:
COM_Invoke(COM_Invoke(pwd, "document"), "getElementById", "Passwd")


What version of IE are you working with? The IEReady() function usually works fine for me on IE 6, but it's not working well for me on IE 8. Perhaps try removing the IEReady() function for now, and use Sleep 5000 (or however long it takes for the page to refresh usually)

Example script:
Load www.Google.com. Run this code (Hotkey: ^d). This will keep refreshing every 3 seconds because the element doesn't exist.
Then pause the script, and click on the Gmail link on the top of the webpage. After this is loaded, unpause the script. The DONE! msgbox should display because now the element exists.
Code:
GetWebBrowser() ; written by Sean
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   If Not   hIESvr
      Return
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}

^d::
COM_Init()
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
    sleep 3000
   if % COM_Invoke(pwd, "document.getElementById[Passwd]")
      break
}
msgbox DONE!
return


Idea EDIT Exclamation
Try completely loading the page you're working with, and run this script:
Code:
^d::
COM_Init()
pwd := GetWebBrowser()
msgbox % COM_Invoke(pwd, "ReadyState")
return

That is the value of "ReadyState" when the page is fully loaded. If this value is not 4, you may be able to alter the IEReady() function to fix the waiting until fully loaded problem:
Code:
IEReady(hIESvr = 0) ; written by Sean
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4 ; <-- Change 4 to different value
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
marcusjb



Joined: 24 Jun 2009
Posts: 35

PostPosted: Mon Jun 29, 2009 5:43 am    Post subject: Reply with quote

I've got IE7, but FFX is my default browser, which the script seems to use when I run it.

can you direct me somewhere I can get someone to write this script for me? I just don't have the time to learn how to use AHK right now. should I go to rentacoder.com or something? any help is appreciated.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Mon Jun 29, 2009 6:12 am    Post subject: Reply with quote

Your script runs FFX because of this line:
Code:
Run file:///C:\code.html

This will run the html file on the default browser. However, FFX is not a COM application; therefore, the COM.ahk Library won't do much good.

Quote:
can you direct me somewhere I can get someone to write this script for me?

Shocked Not too sure about that, especially since . . .
Quote:
I can't provide the actual page because its an internal company site.


One good thing is that Javascript will work with FFX. For instance, put this in the URL address bar, hit enter, and the page will refresh:
Code:
javascript:location.reload(true)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group