Jump to content
MattG1991

Assistance with Javascript and IE

Recommended Posts

MattG1991

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?

Share this post


Link to post
Share on other sites
Juvigy

That is the only thing that line is supposed to do - you don't have any more code to run. What else do you want ?

 

Share this post


Link to post
Share on other sites
junkew

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

Share this post


Link to post
Share on other sites
MichaelHB

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.

Share this post


Link to post
Share on other sites
MattG1991

On the end of the statement, I had to enter a "0" in order for it to run the js and continue. Otherwise, it acted as though it kept reloading or waited for it to navigate to another page. Thanks to all for your assistance!

Share this post


Link to post
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

  • Similar Content

    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • SkysLastChance
      By SkysLastChance
      I have a goofy problem. I am hoping someone could shed some light. The example is not going around the text box. It is way off. 
      I have seen some post blaming IE 11, however I have IE11 on my desktop and it works fine.
      Is there anything I can do that might fix this? 
       
      ; Open a browser with the form example and get a reference to the form ; textarea element. Get the coordinates and dimensions of the text area, ; outline its shape with the mouse and come to rest in the center #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oTextArea = _IEFormElementGetObjByName($oForm, "textareaExample") ; Get coordinates and dimensions of the textarea Local $iScreenX = _IEPropertyGet($oTextArea, "screenx") Local $iScreenY = _IEPropertyGet($oTextArea, "screeny") Local $iWidth = _IEPropertyGet($oTextArea, "width") Local $iHeight = _IEPropertyGet($oTextArea, "height") ; Outline the textarea with the mouse, come to rest in the center Local $iMousespeed = 50 MouseMove($iScreenX, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth, $iScreenY + $iHeight, $iMousespeed) MouseMove($iScreenX, $iScreenY + $iHeight, $iMousespeed) MouseMove($iScreenX, $iScreenY, $iMousespeed) MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed)  
       
    • RamaKrishna9
      By RamaKrishna9
      What are the minimum system requirements(like Windows OS version, IE browser version, etc,.) for IE.au3(3.3.14.2) to work properly?
    • SkysLastChance
      By SkysLastChance
      So I have two things I am trying to click.
      Policy which works.
      $oInputs3 = _IETagNameGetCollection($oIE, "div") For $oInput3 in $oInputs3 If StringStripWS($oInput3.innertext,1) = "Policy" Then $target = $oInput3 _IELoadWait($target,"",70000) ExitLoop EndIf Next _IEAction($target, "click")  

      And Add Insurance which I havent been able to get to work. 
      $oInputs2 = _IETagNameGetCollection($oIE, "div") For $oInput2 in $oInputs2 If StringStripWS($oInput2.innertext,1) = "Add Insurance" Then $target = $oInput2 _IELoadWait($target,"",70000) ExitLoop EndIf Next _IEAction($target, "click")

      Any Ideas on what I am doing wrong?  I feel like it might be the spaces between >  Add Insurance  < but I am not sure. 
    • FMS
      By FMS
      Hello,
      I'm trying to read a div element and wait until it hits 100%.
      The structure is like :
      <div class="progress-bar" style="width: 48.0219%;  overflow: hidden; "></div>
      And want to wait until :
      <div class="progress-bar" style="width: 100%;  overflow: hidden; "></div>
      because afther this there will be an redirection whish i don't know the URL from and want to catsh this URL.
      And want to push a button on this redidertion page.

      Is there a best pratice way how to do this or is there a better way to wait for the redirection?
      Maybe wait until button exist or something?

      Does anybody could give me some tips about this challange?
       
      thnx in advanced.
       
      #include <IE.au3> Global $IE_flvto = _IECreate("https://www.website.com/",0,1,1,1) Global $oForm = _IEFormGetObjByName ($IE_flvto, "convertForm") Global $oText = _IEFormElementGetObjByName ($oForm, "convertUrl") _IEFormElementSetValue ($oText, "some text") _IEFormSubmit($oForm) ;wait for redirection ;if redirection loaded push button  
×