Jump to content

Help needed with IE automation


Recommended Posts

I need to automate a corporate web based login. I have the following code which I recorded using IUI Automation

;~ *** Standard code ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP6=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Authentication Service - Internet Explorer;controltype:=UIA_WindowControlTypeId;class:=IEFrame", $treescope_children) 
_UIA_Action($oP6,"setfocus")
Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame Tab", $treescope_children)    
_UIA_Action($oP5,"setfocus")
Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=Authentication Service - Internet Explorer;controltype:=UIA_PaneControlTypeId;class:=TabWindowClass", $treescope_children) 
_UIA_Action($oP4,"setfocus")
Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell DocObject View", $treescope_children) 
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=https://abc.xyz.com/hsh/Login?GAREASONCODE=-1&GARESOURCEID=abcsi14079c1new4&GAURI=https://abc.xyz.com:12345/klmnop/servlet/MainServlet/home;controltype:=UIA_PaneControlTypeId;class:=Internet Explorer_Server", $treescope_children)  
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Authentication  Service;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children)  
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=log in;controltype:=UIA_HyperlinkControlTypeId;class:=", $treescope_children)  
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("login.mainwindow", "title:=log in;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=log in;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")

I tried this code but it didn't work. Then I went around to read more when I found out that the code needs some changes for it to be useful. Can anyone please help me with that part? I can handle the rest automation which is mostly Windows based.

Link to comment
Share on other sites

Hey friend.  So I would recommend trying this tool.  It is posted in the download section of this site and has been a great help to me in the creation of IE automation scripts.  Run the website containing the login form through this tool and see if this helps at all.  Instead of using whatever information you are trying to use to identify the HTML elements, try using the tool to find their ID #s.

Edited by MattHiggs
Link to comment
Share on other sites

I'm trying to work with it but cannot understand exactly what's happening. It needs parameters by reference which is confusing. Can someone please sort this out by a simple example such as how do i wait until www.facebook.com is completely loaded and then enter the credentials and then press the login button?

 

Edit: I know these functions:

_IELoadWait
_IELinkClickByText

I'm  just not sure how to use them.

Edited by pranaynanda
Link to comment
Share on other sites

And this is what I get when I run this:

#include<IE.au3>
$link=_IECreate("www.secretlink.com")
$a=_IELoadWait($link)
ConsoleWrite($a)
$b=_IELinkClickByIndex($link,14)
ConsoleWrite($b)

The response on console

Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.)
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
0"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (770) : ==> The requested action with this object has failed.:
Local $oLinks = $oObject.document.links, $oLink
Local $oLinks = $oObject^ ERROR
->12:01:12 AutoIt3.exe ended.rc:1
+>12:01:12 AutoIt3Wrapper Finished.
Link to comment
Share on other sites

pranaynanda,

Here the example:

#include <IE.au3>

Local $oIE = _IECreate("https://www.facebook.com")
_IELoadWait($oIE)
If @error Then
    $oIE = _IEAttach("facebook.com", "url")
    If @error Then Exit ConsoleWrite("Error in _IEAttach" & @CRLF & "@error: " & @error)
EndIf

Local $oEmail = _IEGetObjById($oIE, "email")
If @error Then Exit ConsoleWrite("Error in $oEmail" & @CRLF & "@error: " & @error)
_IEFormElementSetValue($oEmail, "email@email.com")
If @error Then Exit ConsoleWrite("Error in _IEFormElementSetValue($oEmail)" & @CRLF & "@error: " & @error)

Local $oPassword = _IEGetObjById($oIE, "pass")
If @error Then Exit ConsoleWrite("Error in $oPassword" & @CRLF & "@error: " & @error)
_IEFormElementSetValue($oPassword, "password")
If @error Then Exit ConsoleWrite("Error in _IEFormElementSetValue($oPassword)" & @CRLF & "@error: " & @error)

Local $oSubmit = _IEGetObjById($oIE, "u_0_m")
If @error Then Exit ConsoleWrite("Error in $oSubmit" & @CRLF & "@error: " & @error)
MsgBox(0, "", "Before click on submit button.")
_IEAction($oSubmit, "click")
If @error Then Exit ConsoleWrite('Error in _IEAction($oSubmit, "click")' & @CRLF & "@error: " & @error)

MsgBox(0, "", "Done!")
Exit

As state by Danp2, _IECreate automatically performs an _IELoadWait by default but as you are getting an error (-2147417848) probably because your browser is internally "jumping" to a different security zone, so because i dont know if you are using a COM error handler, the _IELoadWait will error out (i believe this way will be easier for you to understand) and try to _IEAttach. You can easily adapt this example to fit your needs.

Link to comment
Share on other sites

I see.  So the web page is actually being launched by another application?  In that case, I would suggest you still look at the _IECreate function, more specifically the second parameter about whether or not you want the object reference to attach to a window that already exists.  All of the parameters in _IEcreate are optional, so even if the window already exists, you can create an object that attaches to that window which will then allow you to automate it.

Link to comment
Share on other sites

Also, may or may not help at this point, but as I was able to find a portable application that USED to be available on AutoHotKey's website, and is very useful for those who want to create IE automation scripts.  This is why I locally store any application I find interesting, in the event that it falls off the face of the earth and is no longer available online, I still got it.  First, it only works with IE, but it is a tool which is very similar to the AutoIT Window Info Tool in terms of operation, but instead of providing information about Windows forms, it provides you information about the elements within a loaded webpage.  Very useful to who ever wants it.

iWB2 Learner - 32bit.zip

iWB2 Learner - 64bit.zip

2016-07-17 13_13_31-Greenshot.png

Edited by MattHiggs
Link to comment
Share on other sites

Indeed nice tool.

 

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

There is many work done in IE.au3 rewrite.
I have stuck with documentation.
Do you want to contribute to AutoIt and make some progress with documentation for new IE.au3 ?

 

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Sure. I asked because i was making some modifications for a friend  and they can be implemented in the IE. Like:

  • IECreate with command-line options (‑noframemerging for example, use regread to find the ie installation and PID for the IEAttach method).
  • IENavigate with NavFlags like: navOpenInBackgroundTab
  • I have a querySelectorAll function that is already working fine (with the same standard of other IE functions). very useful func if i may add.
  • There is some redundancies, for example IsObj is checked twice in most functions (the other time is in __IEIsObjType).
  • All the objects colletions should return an array with the objects. For nodecolletion is not recommended the For-In-Next loop, so using an array is 5x times faster than element.item($i), and its at least 2x faster for HtmlElementCollection.

This is what i remember right know, i believe that there is more. The tests that i made is in the initals steps and i have not had the opportunity to test on multiple systems.

Link to comment
Share on other sites

Hey,  Can I ask a somewhat off topic question too?  That software I posted above.  Like I said, it was available on AutoHotkey's website when I was investigating automation solutions for a project back when I was an intern (which is what introduced me to Autoit), but case and point is that, while the tool is still displayed on the main page, trying to download it results in the file hosting service giving the error message equivalent of "file not found" or "file has been removed" or whatever.  So, since I had stored this on my file server, I would like to share it with the AutoIT community.  But I haven't been able to find any rules regarding posting software that you didn't create.  Would it be ok if I did this as long as I announce that this is not my work and credit the use who posted the tool on the autohotkey forum?  Is it altogether disallowed?  This forum has many rules, and while I consider that a good thing, I want to make sure I don't violate any of them.

Link to comment
Share on other sites

I think your question is realated to one of MOD or ADMIN , so you should wait for their ansewers.

 

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

  • 1 month later...

Guys, against as I previously stated, the url does not move to https from http. It starts from https and generates tokens in https which altogether looks like a different URL. This is what I get.

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.)
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IETagNameAllGetCollection, $_IESTATUS_InvalidDataType

This is what I tried

 

#include <IE.au3>

AutoItSetOption("TrayIconDebug",1)

$oIE= _IECreate("https://www.link.com")

$oIE=_IEAttach("https://www.link.com")

_IELoadWait($oIE)
;$button=_IEGetObjByName($oIE,"log in")

;_IEAction($button,"click")

$col=_IETagNameAllGetCollection($oIE)

ConsoleWrite($col)

Also, the action that I wanna do is click on a span class which I have no idea about what it is so I'm assuming traditional method does not work.

Edited by pranaynanda
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...