Jump to content

_IE and Javascript


Recommended Posts

----------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 by cascius
Link to comment
Share on other sites

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
Next

So 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

  • 3 years later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...