Jump to content

Assistance with Javascript and IE


Recommended Posts

Hello everyone. I've a quick question. And yes, I am fairly new to AutoIt (in case you were wondering). 

I'm writing a program that will open a webpage and inject Javascript code into the address bar. 

_IENavigate($oie, "javascript:var oArray = document.getElementsByClassName('tab_caption'); for(i = 0; i < oArray.length; i++) { if(oArray.innerHTML == 'Information') oArray.click(); };")

The line clicks on the tab listed as "Information", then it doesn't continue. Is there a way I can make AutoIt run this command for a specified amount of time, then move on to the next line of code?

Link to comment
Share on other sites

yes, you can if in your javascript line you make something at the end like alert("finished"); and have autoit check for that box.

If you do not like the alert you can also choose to add html element and have autoit check for that

of open a tcp socket in the javascript and ping autoit script but that seems to complex for solving your problem (for https thats even terrible, for http its not that hard)

 

 

Edited by junkew
Link to comment
Share on other sites

I would first make sure that the website is fully load before trying to make any selection (.busy = false / .readystate = 4). Then you have some options, you can easily use _IEHeadInsertEventScript (you can also add some modification to any label/text in the website to check later if the java is done), or you can make this in autoit, something like this:

#include <IE.au3>

Local $oaTab_Captions, $oTab_Caption

$oIE = _IECreate("URL") ; make sure its fully loaded

$oaTab_Captions = $oIE.document.getElementsByClassName("tab_caption")
If Not IsObj($oaTab_Captions) Then Exit MsgBox(0, "ERROR", "Error in $oaTab_Captions")

For $oTab_Caption In $oaTab_Captions
    If $oTab_Caption.innerHTML = "Information" Then $oTab_Caption.Click()
Next

Exit

 

Edited by MichaelHB
insert link.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...