Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Need some help with COM


  • Please log in to reply
9 replies to this topic
beny
  • Guests
  • Last active:
  • Joined: --
Hey guys I've been trying to make this scrip to open a browser in the GUI then log into this site called tumblr(specifically tumblr.com/login) using this script.

This is my code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Include COM.ahk
Login(userinput1,userinput2)
{
	COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('email').value='" userinput1 "';void(0)")
	Sleep, 100
	COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('password').value='" userinput2 "';void(0)")
	Sleep, 100
	COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('account_form').submit();")
}
InputBox, user1, Login, Email:,, 200, 125,,,,,
Inputbox, user2, Login, Pass:,HIDE,200,125,,,,,

Gui +LastFound
COM_AtlaxWinInit()  
pwb:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(), 0, 0, 800, 400, "shell.explorer") )
COM_Invoke(pwb, "Navigate", "http://www.tumblr.com/dashboard")
Gui, Show, x12 y162 h400 w800, Bot

Login(user1,user2)
return

GuiClose:
Exitapp

Now the thing is, when I run this it loads up the gui and browser fine, but then I get this error:
---------------------------
COM Error Notification
---------------------------
Function Name:	"Navigate"
ERROR:	The COM Object may not be a valid Dispatch Object!
	First ensure that COM Library has been initialized through COM_Init().
	()

Will Continue?
---------------------------
Yes   No   
---------------------------

I've searched a bunch, and to be honest I'm stumped.
Can someone help me out?

On Another note, can anyone help with with the javascript to select the password field on this login page? I've been able to get the email field as well as the submit button but the password field has been throwing me off.
Thanks!

sinkfaze
  • Moderators
  • 6365 posts
  • Last active:
  • Joined: 18 Mar 2008
You only need to use the Navigate parameter for just that, navigating to a website. After that you just call to the elements themselves. I believe this is correct:

Login(userinput1,userinput2)
{
   COM_Invoke(pwb, "document.getElementById[email].value", userinput1)
   COM_Invoke(pwb, "document.getElementById[password].value", userinput2)
   COM_Invoke(pwb, "document.getElementById[account_form].submit")
}


tank
  • Moderators
  • 4192 posts
  • Last active: Today, 01:54 AM
  • Joined: 21 Dec 2007
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases. 

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability. 

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory. 



#Include COM.ahk 

Login(userinput1,userinput2) 

{ 

   COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('email').value='" userinput1 "';void(0)"[color=red],0x0400[/color]) 

   Sleep, 100 

   COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('password').value='" userinput2 "';void(0)"[color=red],0x0400[/color]) 

   Sleep, 100 

   COM_Invoke(pwb, "Navigate", "javascript:document.getElementById('account_form').submit();"[color=red],0x0400[/color]) 

} 

InputBox, user1, Login, Email:,, 200, 125,,,,, 

Inputbox, user2, Login, Pass:,HIDE,200,125,,,,, 



Gui +LastFound 

COM_AtlaxWinInit()  

pwb:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(), 0, 0, 800, 400, "shell.explorer") ) 

COM_Invoke(pwb, "Navigate", "http://www.tumblr.com/dashboard") 

Gui, Show, x12 y162 h400 w800, Bot 



Login(user1,user2) 

return 



GuiClose: 

Exitapp
the red should help but Sinkfaze suggestion is actually more appropriate

beny
  • Guests
  • Last active:
  • Joined: --
Thanks so much to both of you. I'll give this whirl when I get home :)

beny
  • Guests
  • Last active:
  • Joined: --
I was able to try it here, and I tried both ways but I'm still getting the error.

Any ideas?

tank
  • Moderators
  • 4192 posts
  • Last active: Today, 01:54 AM
  • Joined: 21 Dec 2007
Sinkfaze code would not give you the same error because it doesnt use navigate

better check again

beny
  • Guests
  • Last active:
  • Joined: --
Oh sorry about that. Its almost identical, thats why I said it was the same:

---------------------------
COM Error Notification
---------------------------
Function Name:	"document"
ERROR:	The COM Object may not be a valid Dispatch Object!
	First ensure that COM Library has been initialized through COM_Init().
	()

Will Continue?
---------------------------
Yes   No   
---------------------------


beny
  • Guests
  • Last active:
  • Joined: --
Ok this is odd. When I take the code out of the function and just put it after the main body of code, it works?

Do I need to recall the window in the function or something?

Btw Thanks again

sinkfaze
  • Moderators
  • 6365 posts
  • Last active:
  • Joined: 18 Mar 2008

Ok this is odd. When I take the code out of the function and just put it after the main body of code, it works?

Do I need to recall the window in the function or something?


No, you need to ensure that your COM calls inside the function have access to the same pointer you created outside of the function:

Login(userinput1,userinput2) {

   [color=red]global pwb[/color]

   COM_Invoke(pwb, "document.getElementById[email].value", userinput1)
   COM_Invoke(pwb, "document.getElementById[password].value", userinput2)
   COM_Invoke(pwb, "document.getElementById[account_form].submit")

}

InputBox, user1, Login, Email:,, 200, 125,,,,,
Inputbox, user2, Login, Pass:,HIDE,200,125,,,,,

Gui +LastFound
COM_AtlaxWinInit() 
[color=red]pwb[/color]:=COM_AtlAxGetControl(COM_AtlAxCreateContainer(WinExist(), 0, 0, 800, 400, "shell.explorer") )
COM_Invoke(pwb, "Navigate", "http://www.tumblr.com/dashboard")
Gui, Show, x12 y162 h400 w800, Bot

Login(user1,user2)
return

GuiClose:
Exitapp


beny
  • Guests
  • Last active:
  • Joined: --
Bingo, that did it.
Thanks for all the help guys, I really appreciate it :)