Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved]COM Object (Internet Explorer)



  • Please log in to reply
11 replies to this topic
Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

I tried this code earlier today.

It works fine with me.

e  := ComObjCreate( "InternetExplorer.Application" ) 
e.Navigate( "https://www.freetm.com/" )                          
While e.Busy  ||   e.ReadyState  <>  4  
  Sleep, 99
e.Visible := True

Now,  I want to put in two things (ID/PW) and click the button ("Connect") once.

But, I have NO idea what do I have to do.

 

I found some lines from the html source(do not know the exact name though).

I goes like this;

<input class="gwt-TextBox" style="width: 200px;" type="text" />
<input class="gwt-PasswordTextBox" style="width: 200px;" type="password" />
<button class="gwt-Button" type="button" >

The first one looks "ID", the next is "PW" and the last is "Connect" button, I guess.

So, What code do I have to use ? for COM Object ? (I am using IE9)

 

Show me the way please.

 

Thanks.

 

 

 

 

 

Followings are "Some" codes, I do not understand (though I do tried several dozen times/hours, But I have failed to understand it.)

e.document.getElementsById( "Something").innerText
e.document.getElementsByTagName( "Something" )[5].value := Var
e.document.Search2.Key.Value := "Something"
Fr  :=  e.document.getElementsByTagName( "form" )[0] 
Fr.q.value := Clipboard
e.Document.Search2.Submit()


Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

I'll answer the first question:
What is there after the 'e' is javascript.
Suppose if the html source is like this:

<input class="gwt-TextBox" style="width: 200px;" type="text" />
<input class="gwt-PasswordTextBox" style="width: 200px;" type="password" />
<button class="gwt-Button" type="button" >

The AHK code to add text to the fields and press the submit button can look something like this:

e.document.getElementsByClassName("gwt-TextBox")[0].value := "USERNAME" 

document.getElementsByClassName("gwt-TextBox")  gets all the elements which has the class 'gwt-TextBox'. 'document' is a javascript object. getElementsByClassName("gwt-TextBox") is a method of that object.
This method returns a html collection or, something like an array. so we have to specify the '[0]' to use the 1'st item in the array. (Javascript arrays are zero based or it starts from zero.)
Then we have the '.value' part. '.value' is a property which contains whatever is written in the input field. Then we set to whatever we want.

Then the password field:




e.document.getElementsByClassName("gwt-PasswordTextBox")[0].value := "PASSWORD"

It's the same thing, but different class names.

Then lastly, to click the button, we first get the element using the getElementsByClassName method. Then we stimulate a click with the click() method.

e.document.getElementsByClassName("gwt-Button")[0].click()

You can test this out with a normal browser either chrome or ff. Just open developer tools>Javascript console.
and test the stuff out. But you wouldn't need to add the 'e.' before the code.
You can learn more about the methods and functions here: https://developer.mo...eb/API/Document



lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

Hi Hamlet,

 

For a general overview of IE COM with AutoHotkey you might try this post.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

Thanks ! Menixator !!

I did not have any knowledge about the Java.
That's why I had had so so hard time.
Your kind explanation widen my eyes.
Thanks again.


-I am adding, a tiny result of my trial.
 I put one line between mine and yours.

Sleep, 1234

It looks silly, but it is not actually.
It has Great importance to me.
Without it ? It makes errors only.
-Error:  0x80020006 - 알 수 없는 이름입니다(UnKnowin names).
It works somewhere around 500msec though, I put some margins so, it is 1234.

One more thing.
I put (ported) the three line into MS Word VBA.
It gave me compile errors.
Any idea ?

Thanks, you are a good one.
 



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

>lifeweaver

 

Thanks, I skimmed that one sometime earlier.

I will check it out throughly again.



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

First of, Hamlet, it's Javascript, not JAVA.
Java is an advanced programming language and is totally different from javascript.
And secondly, here is an example of how you'd work with vbscript:

dim Ie
set Ie = Wscript.CreateObject("InternetExplorer.Application")
Ie.visible = true
Ie.Navigate "http://www.google.com"
while Ie.ReadyState <> 4
	Wscript.sleep 100
wend
Wscript.Echo "Finished Loading."

There might be errors. :)
I'm not good with vbscript.



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

Thanks ! Again, Menixator !!

 

Really..

Java is different from Javascript.

OK, that will be some homework.

 

Now.

Sorry, I forgot to put my codes up here.

I goes like this.

Dim ID: ID = "Java"
Dim PW: PW = "Javascript"
Dim e
Set e = CreateObject("InternetExplorer.Application")
    e.Visible = 1
    e.Navigate ("https://www.freetm.com/")
    While e.Busy Or e.ReadyState <> 4: Wend

'   e.document.getElementsByClassName("gwt-TextBox")[0].value = ID
'   e.document.getElementsByClassName("gwt-PasswordTextBox")[0].value = PW
'   e.document.getElementsByClassName("gwt-Button")[0].click()

I commented the last 3 lines. Because it make compile error at "[ 0 ]" part.

(OR, If I changed that part into this, "( 0 )" still did not work with different error message.)

Excpet those, All lines work fine.

 

I know it is not the AHK, but VBA problem (I am not so sure about it 100%, It could be the problem from Javascript, maybe..)

 

I hope somebody who knows both (or theree) of them help me out.

 

Regards..



Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

Arrays are accessed with (0), hmm . . that was news for me.
Anyways, i think i found the problem. The login box doesn't appear till a few seconds after the page has been fully loaded.
So, even after the page has been fully loaded, we have to wait till the login box appears. Right after the page has been loaded, it doesn't exist, so it gives an error.

dim Ie
set Ie = Wscript.CreateObject("InternetExplorer.Application")
Ie.visible = true
Ie.Navigate "https://www.freetm.com/"
while Ie.ReadyState <> 4
	Wscript.sleep 100
wend
Wscript.sleep 1500
Ie.document.getElementsByClassName("gwt-TextBox")(0).value="Menixator"
Ie.document.getElementsByClassName("gwt-PasswordTextBox")(0).value = "Menixator's Password"
Ie.document.getElementsByClassName("gwt-Button")(0).click()

btw, the wait time after the full loading entirely depends on the speed of the connection/browser.



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

This part never works for me.

Do I need some kind of settings (reference or sometihg at VBA Editor) ?

set Ie = Wscript.CreateObject("InternetExplorer.Application")

Error message says, "Need object".

 

 

Thanks.

 

 

 

PS)

So, This line works for you ? Without any kind of error messages ?

Ie.document.getElementsByClassName("gwt-TextBox")(0).value="Menixator"


Menixator
  • Members
  • 744 posts
  • Last active: Sep 01 2015 02:54 PM
  • Joined: 10 Jul 2013

Do I need some kind of settings (reference or sometihg at VBA Editor) ?

Sorry, I don't know.
 

So, This line works for you ? Without any kind of error messages ?

Ie.document.getElementsByClassName("gwt-TextBox")(0).value="Menixator"

Yes. The whole script works flawlessly for me.



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

Maybe my environment has problem, I guess.

Vist 32bit/Word 2003/IE9

 

Anyway, it was good to hear from you some nice tip.

 

Thanks. Really.



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009
✓  Best Answer

I solved the problem a little bit by myslef.

 

 

First, VBA needs (desperately) some "pause time" too, as in AHK.

I put 5secs.

Works fine with me.

 

 

Secondly,

It needs something like the dummy numbers in it (I mean clicking action).

 

 

Without the dummy, It never works out. It has compilation errors all the time.

e.Document.getElementsByClassName("gwt-Button")(0).click()

..

..

.

 

 

You know what, This one works fine all of a sudden.

e.Document.getElementsByClassName("gwt-Button")(0).click(0)

I just put a "zero" inside without any kind of smart intention. Anyway it works.

 

If you want 1, 2, 3 insteady of zero ?  OK, go ahead, you are the boss.

 

 

 

The meaning of that numbers ?

Tell me please I will appreciate it, Really.

(It is really worse than you think. If it loose "some control", it make a real mess with MS Word. MS Word dies.)

 

 

 

 

Bye.