Priti Posted October 30, 2015 Share Posted October 30, 2015 (edited) Hi,I am a noob. I just recently started using AutoIT to automate a few tasks at work. After the initial success with simple repetition of login routine on simple web e-mail accounts, I tried automating a little more complex process in SAP. I am now able to open the web page, which is the WebGUI of SAP, click a web link and then again click another web link. So far, so good. However, now I have encountered a link that is actually a Java one. I have tried to fire it with various techniques and codes, but it just doesn't work.See below the code for the Java link as seen through the Inspect Element:<a onclick="return htmlbDoEvent(this,'C','onclick','0','htmlb_69877_0',6,1,'',0);" id=Link788381c5 title="Shopping Cart" class=urLnkDragRelate onkeydown="return (sapUrMapi_Link_activate('Link788381c5',event))" href="javascript:void(0)" target="" ct="LN" st=""><SPAN class=urTxtStd ct="TV">Shopping Cart</SPAN></a>As you can see, when the user clicks the Shopping Cart text it executes a Java Function Link788381c5. The problem is, that the numbers change for each and every session. Please find below the code that I have written so far: expandcollapse popup#include <SAP.au3> #include <ie.au3> ;Minimizes all windows on the desktop WinMinimizeAll() ;Declaring variables that would be used through the program Local $oUser, $oPass, $oSubmit, $oInput, $oLink, $oLinkFrame ;Variable for launching the browser window $oIE = _IECreate ("https://supplierconnect.abc.com/irj/portal") _IELoadWait($oIE) ;Checks if the window is maximized, if not, it maximizes it If WinExists("Universal Worklist - SAP NetWeaver Portal") Then WinSetState("Universal Worklist - SAP NetWeaver Portal", "", @SW_MAXIMIZE) Sleep(2000) ;Searches for the link and clicks it when it finds $oLinks = _IETagNameGetCollection($oIE, "a") For $oLink In $oLinks If String($oLink.id) = "navNodeAnchor_1_2" And String($oLink.tabindex) = "-1" Then _IEAction($oLink, "click") ExitLoop EndIf Next _IELoadWait($oIE, 1000) Sleep(3000) ;Searches for the link and clicks it when it finds $oLinks = _IETagNameGetCollection($oIE, "a") For $oLink In $oLinks If String($oLink.id) = "navNodeAnchor_2_1" And String($oLink.tabindex) = "-1" Then _IEAction($oLink, "click") ExitLoop EndIf Next _IELoadWait($oIE, 1000) Sleep(3000) ;Searches for the Shopping Cart link and clicks it when it finds ;This is the problem area. All the code snippets found below try to click the link one way or the other, without any success $oLinks = _IETagNameGetCollection($oIE, "a") For $oLink In $oLinks If String($oLink.title) = "Shopping Cart" And String($oLink.classname) = "urLnkDragRelate" And String($oLink.href) = "javascript:void(0)" Then $oIE.document.parentwindow.execScript('void(0);', 'javascript') _IELinkClickByText($oLink, "Shopping Cart", 0, 1) $oLink.fireEvent("onclick") ExitLoop EndIf Next _IELoadWait($oIE, 1000) ; Second code snippet that tries to fire the Java link without success ; find IFrame object which contain this Map element object Local $oIEFrame = _IEFrameGetObjByName($oIE, 'urGridLayout') ; get Map element object by reference to IFrame Local $oIEMap = _IEGetObjByName($oIEFrame,'Shopping Cart') ; click in Map element object _IEAction($oIEMap,'click') ;Third code snippet that tries to fire the Java link without success $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended For $i=0 to ($iNumLinks - 1) $oLink = _IELinkGetCollection($oIE,$i) If $oLink.href = "javascript:void(0);" Then _IELinkClickByIndex($oIE,$i ) $oLink.fireEvent("onclick") Exit EndIf Next EndIfI use AutoIT v3.3.14.2 and WebGUI of SAP. Also, the OS is Windows 7 Enterprise and the browser is IE11. Any help in resolving the issue is highly appreciated. Eagerly look forward to your inputs.Thanks & Regards,Priti Edited October 30, 2015 by Priti Forgot to mention the OS Link to comment Share on other sites More sharing options...
mLipok Posted October 30, 2015 Share Posted October 30, 2015 (edited) Please read: How to post code on the forum And this: ie.au3 UDF with AutoIt v3.3.14.x and show Console output. EDIT: IE Version ? Edited October 30, 2015 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Priti Posted October 30, 2015 Author Share Posted October 30, 2015 Console Output:>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /NoStatus /prod /in "C:\Users\XXXX\Desktop\SAP-Test.au3" +>22:16:37 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0 Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\XXXX\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\XXXX\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\XXXX\Desktop\SAP-Test.au3 +>22:16:37 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\aut2exe\aut2exe.exe /in "C:\Users\XXXX\Desktop\SAP-Test.au3" /out "C:\Users\XXXX\AppData\Local\AutoIt v3\Aut2exe\~AU88C2.tmp.exe" /nopack /comp 2 +>22:16:39 Aut2exe.exe ended.C:\Users\XXXX\AppData\Local\AutoIt v3\Aut2exe\~AU88C2.tmp.exe. rc:0 +>22:16:39 Created program:C:\Users\XXXX\Desktop\SAP-Test.exe +>22:16:40 AutoIt3Wrapper Finished. >Exit code: 0 Time: 3.376 Link to comment Share on other sites More sharing options...
mLipok Posted October 30, 2015 Share Posted October 30, 2015 $oLinks = _IETagNameGetCollection($oIE, "a") For $oLink In $oLinks If StringInStr($oLink.outerHTML,'return htmlbDoEvent(this') <>0 Then _IEAction($oLink, "click") ExitLoop EndIf Next _IELoadWait($oIE, 1000) Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Priti Posted October 31, 2015 Author Share Posted October 31, 2015 (edited) Hi mLipok,You are simply awesome. You resolved the issue that was driving me crazy for a whole three days in minutes. And to top it all, you made it look soooo simple. It is the hallmark of great guys to make even the most difficult things look so simple. Take a bow.Well, it resolved one issue and as is the case with most automation efforts, now I bumped into the next. The code is now able to fire the java link, but since there are more than 10 java links on the page and all of them essentially has the same onclick code, it is firing the first one that it encounters. In the onclick code for all the java links on the page:return htmlbDoEvent(this,'C','onclick','0','htmlb_76602_0',6,1,'',0);only the htmlb_XXXXX_0 keeps changing in the code. Everything else in the code remains static. The number after htmlb_XXXXX_0, i.e., 6 in the current instance, is the unique identifier of the link. <A onclick="return htmlbDoEvent(this,'C','onclick','0','htmlb_76602_0',6,1,'',0);" id=Link385c1c82 title="Shopping Cart" class=urLnkDragRelate onkeydown="return (sapUrMapi_Link_activate('Link385c1c82',event))" href="javascript:void(0)" target="" ct="LN" st=""><SPAN class=urTxtStd ct="TV">Shopping Cart</SPAN></A>If the code could just ignore the htmlb_XXXXX number, in the current instance it is 76602, but validates the rest of the string, then we should be good.Resolving it must be like a stroll in the park for you, but it sure is no less than climbing a mountain for me.Eagerly look forward to your advise in the matter.With Warm Regards,Priti Edited October 31, 2015 by Priti Link to comment Share on other sites More sharing options...
mLipok Posted October 31, 2015 Share Posted October 31, 2015 like this ? #include <MsgBoxConstants.au3> #include <StringConstants.au3> #cs <A onclick="return htmlbDoEvent(this,'C','onclick','0','htmlb_76602_0',6,1,'',0);" id=Link385c1c82 title="Shopping Cart" class=urLnkDragRelate onkeydown="return (sapUrMapi_Link_activate('Link385c1c82',event))" href="javascript:void(0)" target="" ct="LN" st=""><SPAN class=urTxtStd ct="TV">Shopping Cart</SPAN></A> #ce _Example() Func _Example() Local $sStringToCheck = ClipGet() MsgBox(0, 'TEST1', _ StringRegExp($sStringToCheck, "onclick=""return htmlbDoEvent\(this,'C','onclick','0','htmlb_\d+_0',6,1,'',0\);", $STR_REGEXPARRAYMATCH) _ ) Local $aCheck = StringRegExp($sStringToCheck, "onclick=""return htmlbDoEvent\(this,'C','onclick','0','(htmlb_\d+_0)',6,1,'',0\);", $STR_REGEXPARRAYGLOBALMATCH) If @error Then MsgBox($MB_ICONERROR, '$aCheck', '@error = ' & @error & @CRLF & '@extended = ' & @extended) Else MsgBox(0, 'TEST2', $aCheck[0]) EndIf EndFunc ;==>_Example Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 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