Jump to content

_IEAction 'click' is not working properly


RohanM
 Share

Recommended Posts

Hello Friends,

I am new to autoIt and new to this forum as well,

I have one web form which has <a> tag, once it clicks it will open some content on the frame, <a>  tag dose not have id and I am handling with click event, now the problem first time it will work perfectly but if I run second time _IEAction() click is not working, but if I clear the IE browser history and run then script will work. code is given below, please help me to find the issue. 

 

$oLinks = _IETagNameGetCollection($oIE, 'a')
            For $oLink In $oLinks
                $sRef = $oLink.getAttributeNode('onclick').NodeValue
                If StringInStr($sRef, "javascript:PrintTrack('#abc-1')") > 0 Then
                    _IEAction($oLink, 'click')
                    ExitLoop
                EndIf
            Next

Link to comment
Share on other sites

Link to comment
Share on other sites

  No tag is not in the frame its inside the div once its clicked it will open print page                               

<div class="print-download-blk right hideClass" id="printBtns" data-html2canvas-ignore="">
<a class="print-link red-btn " onclick="javascript:PrintTrack('#card-1')" href="#">
Print
<img width="9" height="12" src="/images/print-icon.png">
</a>
 </div>

Link to comment
Share on other sites

Yes your correct there is the deference in my link and the search text, that I have given as a sample actual code given below 

        $oLinks = _IETagNameGetCollection($oIE, 'a')
        For $oLink In $oLinks
            $sRef = $oLink.getAttributeNode('onclick').NodeValue
            If StringInStr($sRef, "javascript:PrintTrack('#card-1')") > 0 Then
                _IEAction($oLink, 'click')
                ExitLoop
            EndIf
        Next
 

As you suggest, I tried to catch the event by_IELinkClickByText but no luck, while executing I am getting below error on the console and its not getting clicked, but text "Print" is already available.

Print  --> IE.au3 T3.0-2 Warning from function _IELinkClickByText, $_IESTATUS_NoMatch

Link to comment
Share on other sites

  • 3 months later...

Hi Danp2,

I am extremely sorry did not reply to your comment.

 Basically what I am trying to achieve here is, there is a anchor tag with injected java script on onclick event. I want script to find this anchor tag and click it. below is the html

 this is my autoit script

$oLinks = _IETagNameGetCollection($oIE, 'a')
        For $oLink In $oLinks
            $sRef = $oLink.getAttributeNode('onclick').NodeValue
            If StringInStr($sRef, "javascript:PrintTrack('#card-1')") > 0 Then
                _IEAction($oLink, 'click')
                ExitLoop
            EndIf
        Next

 

<div class="print-download-blk right" id="printBtns" data-html2canvas-ignore="">
                                            <a class="print-link red-btn " onclick="javascript:PrintTrack('#card-1')" href="#">
                                                Print
                                                <img width="9" height="12" src="/images/print-icon.png">
                                            </a>
                                            <a class="download-link red-btn" onclick="javascript:printPDF('#card-1')" href="#card-1">
                                                Download
                                                <img src="/images/download.svg">
                                            </a>

                                        </div>

image.png

Link to comment
Share on other sites

Only further suggestion I have is to add some logging to your code so that you can determine if the correct element is being found --

$oLinks = _IETagNameGetCollection($oIE, 'a')
For $oLink In $oLinks
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oLink.outerHTML = ' & $oLink.outerHTML & @CRLF) ;### Debug Console
    $sRef = $oLink.getAttributeNode('onclick').NodeValue
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sRef = ' & $sRef & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    If StringInStr($sRef, "javascript:PrintTrack('#card-1')") > 0 Then
        _IEAction($oLink, 'click')
        ExitLoop
    EndIf
Next

 

Link to comment
Share on other sites

Does your script install a COM error handler? That would explain the warning message.

I'm not sure how we can help further without being able to check out the website.

P.S. It's generally better to post the actual text instead of a screenshot. See here for the proper way to post code / console output.

Link to comment
Share on other sites

Hi Danp2,

thanks for your support, I am not able to publish whole webpage since its contains some sensitive information, however, Instead of firing "click" event I execute the svascript using "$oIE.document.parentwindow.execScript" and it works.

 

 

 

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

  • Recently Browsing   0 members

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