RohanM Posted September 23, 2021 Posted September 23, 2021 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
Nine Posted September 23, 2021 Posted September 23, 2021 If the tag is inside a frame (on the second time), you need to enter the frame before you can access it...Search forum to see how to enter a frame with IE “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
RohanM Posted September 23, 2021 Author Posted September 23, 2021 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>
Danp2 Posted September 23, 2021 Posted September 23, 2021 Have you tried using_IELinkClickByText? _IELinkClickByText($oIE, 'Print') Something else I noticed is that your StringInStr check will fail on the link you posted above. Maybe you could eliminate the variable portion and just check for "javascript:PrintTrack('#". Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted September 24, 2021 Author Posted September 24, 2021 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
Danp2 Posted September 24, 2021 Posted September 24, 2021 I think you need to take a step back and reexamine the situation. If the link exists yet neither option works (your loop and _IELinkClickByText), then the only conclusion I can draw is that it is located inside a frame. Can you tell us more about the target site? What's the URL? Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted January 13, 2022 Author Posted January 13, 2022 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>
Danp2 Posted January 13, 2022 Posted January 13, 2022 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 Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted January 13, 2022 Author Posted January 13, 2022 Thanks for your prompt reply. Yes, correct element found, while while clicking its getting some warning message in the console and print popup is not getting open.
Danp2 Posted January 13, 2022 Posted January 13, 2022 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted January 17, 2022 Author Posted January 17, 2022 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.
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