cascius Posted March 26, 2010 Share Posted March 26, 2010 (edited) ----------SOLVED---------- See my last post for solution. -------------------------- Hi guys, I was reading through IE.au3 but didn't find a function to run a javascript. I did find _IEHeadInsertEventScript, but my understanding is that this will add JS code to the header, not run it. In my case, I already have the javascript function DoSomething() in the header and just want to call it. Can anyone help me? I feel I'm missing something obvious :s Thanks, - Cascius Edited March 27, 2010 by cascius Link to comment Share on other sites More sharing options...
CanHasDIY Posted March 26, 2010 Share Posted March 26, 2010 What are you trying to do? There may be an easier way... Be nice to the newbies... we were all there once...[size="3"]Being right too soon is socially unacceptable. - R. Heinlein[/size]My Projects:OpenKiosk Browser Link to comment Share on other sites More sharing options...
cascius Posted March 26, 2010 Author Share Posted March 26, 2010 Essentially I'm trying to automate some actions on one of my site.Right now I have a script parsing through the HTML looking for an item with a certain innerText, and click it. That item has a javascript attached to it. I've been getting various results with this: sometimes the script thinks it has performed the click but nothing happens; some other times it works just fine...The things is, rather than going through this complex parsing and then trying that click, I'd rather use the function attached to it directly. In the following example it would be: "DoSomething(2,22)"Here's a simplified example:Sample page content<div id="navigation"> <a onclick="DoSomething(1,22);return false;" class="button"><span>Do Something 1</span></a> <a onclick="DoSomething(2,22);return false;" class="button"><span>Do Something 2</span></a> <a onclick="DoSomething(3,22);return false;" class="button"><span>Do Something 3</span></a> </div>Sample Au3 script$DoSomethingDiv = _IEGetObjByName($oIE, "navigation") ;Find "navigation", the container of those links: $DoSomethingLinks = _IETagnameGetCollection($DoSomethingDiv, "a") ;Create a collection of all the links within "navigation" For $DoSomethingLink In $DoSomethingLinks ;Loop through the collection of links $DoSomethingLinkText = $DoSomethingLink.innerText ;Get the innerText of each link If StringInStr($DoSomethingLinkText, "Do Something 2") Then ;check if the innerText matches the value "Do something 2" _IEAction($DoSomethingLink, "click") ;Click the link _IELoadWait($oIE, 0, 7000) ;Wait for page to be loaded ExitLoop EndIf NextSo what's really annoying is that "_IEAction($DoSomethingLink, "click")" doesn't always work in this case. I have it working flawlessly elsewhere, but this one is bugging me. Since I already know the JS function would be "DoSomething(2,22)", I'm thinking there might be a way to avoid all this hassle and just invoke it.Does it make sense?Thanks,- Cascius Link to comment Share on other sites More sharing options...
cascius Posted March 27, 2010 Author Share Posted March 27, 2010 Solved! Here's what I used: $oIE.document.parentwindow.execScript('DoSomething(1,22);') I hope this will be useful to someone. - Cascius Gianni and mLipok 2 Link to comment Share on other sites More sharing options...
lovett1991 Posted March 20, 2014 Share Posted March 20, 2014 +1 Very useful, the developer for our pages left out id's/names for many objects making somethings impossible without directly calling Jscript! Thankyou Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now