Jump to content
Sign in to follow this  
nooneclose

[SOLVED] How do I use the IE UDF to click on a button on a webpage.

Recommended Posts

Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.

HTML Code: 

<img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false">

Here is the code that I have so far:

;*******************************************************************************
; Opens IE and fill out a New Workorder
;*******************************************************************************

; Start IE at the ** Tracking Application in ******
$oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage")

; Wait for a browser page load to complete
_IELoadWait($oIE)

Sleep(6000)

; Store the field names where the important data will be sent
Local $nWorkOrderB   = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image")

_IEAction($nWorkOrderB, "click")

 I want my program to click on the button that looks like a piece of paper with a blue # 

(For those wondering, I am allowed to send images just not the URL.) 

As always any help would be appreciated. 

Screenshot (135).png

Edited by nooneclose

Share this post


Link to post
Share on other sites

When I tried using:

Local $nWorkOrderB   = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image")

_IEImgClick($oIE, $nWorkOrderB, "id")

I got this error: " "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (828) : ==> The requested action with this object has failed.: Local $sModeLinktext, $iFound = 0, $oImgs = $oObject.document.images Local $sModeLinktext, $iFound = 0, $oImgs = $oObject^ ERROR "

Share this post


Link to post
Share on other sites

Same error: 

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (828) : ==> The requested action with this object has failed.:
Local $sModeLinktext, $iFound = 0, $oImgs = $oObject.document.images
Local $sModeLinktext, $iFound = 0, $oImgs = $oObject^ ERROR

Code i used:

 _IEImgClick($oIE, "toolactions_INSERT-tbb_image", "id")

 

Share this post


Link to post
Share on other sites

The result from that code:

; Store the field names where the important data will be sent
Local $nWorkOrderB   = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image")

_IEAction($nWorkOrderB, "click")

1. IE is opened and the webpage is loaded up

2. No error but nothing gets clicked

3. The script ends (i have a message box telling me when the script starts and ends)

 

So that code works but doesn't actually work. Syntactically it is fine but logically something is amiss because the button or image (whatever it is) did not get clicked.

Maybe if I click it twice it will work?  

Share this post


Link to post
Share on other sites

I just noticed the errors i got:

IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147023174, Browser has been deleted prior to operation.)
IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
IE.au3 T3.0-2 Error from function _IEGetObById, $_IESTATUS_InvalidObjectType
IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType
IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

I do not understand the I.E. UDF that much. How am I using the wrong DataType? 

Share this post


Link to post
Share on other sites

I am not sure if you read my first post or read the HTML code but the button/image does not have a name. none the less here is the code I tried:

$oIE = _IECreate("https://....")

; Wait for a browser page load to complete
_IELoadWait($oIE)
Sleep(7000)

; Attach to a browser control embedded in another window
Local $oIE = _IEAttach("A Window Title", "embedded")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & '    Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console


; Store the field names where the important data will be sent
Local $nWorkOrderB   = _IEGetObjByName($oIE, "toolactions_INSERT-tbb_image")

;_IEImgClick($oIE, "toolactions_INSERT-tbb_image", "id")

Sleep(1000)
_IEAction($nWorkOrderB, "focus")
_IEAction($nWorkOrderB, "click")

And here are the errors I got:

IE.au3 T3.0-2 Error from function _IEGetObjByName, $_IESTATUS_InvalidDataType
IE.au3 T3.0-2 Error from function _IEAction(focus), $_IESTATUS_InvalidDataType
IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

Share this post


Link to post
Share on other sites

I'm confused by your post. First you use _IECreate with no indication of an embedded browser. Then you use _IEattach with the embedded option. That doesn't make sense to me.

You also didn't show the results of your Consolewrite, but I assume the _IEAttach was successful because you didn't show any error related to this. However the errors you posted indicate that your $oIE object is invalid, so you'll need to figure out what's up with that.

Are you even allowed to name the application? Perhaps something from IBM? B)

Share this post


Link to post
Share on other sites

1. You told me to try _IEAttach. 

2. I do not know this UDF at all. hence that's why I am asking these questions.

3. I did not see the console write the first few times. Here they are: 

@@ Debug(237) : $oIE = 0
>Error code: 7    Extended code: 0x00000001

4. I do not know how to figure out what's wrong with my $oIE object. 

5. Yes, I can name the application 

6. Yes,  it is from IBM 

Is there a way for me to ring for others to help as well? (I would like to see more opinions on this matter) 

@water 

@JLogan3o13

Edited by nooneclose

Share this post


Link to post
Share on other sites

@@ Debug(238): $oIE = 0 > Error code: 0 Extended code:0x00000000

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147023174, Browser has been deleted prior to operation.)
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
--> IE.au3 T3.0-2 Error from function _IEAttach, $_IESTATUS_InvalidValue (Invalid Mode Specified)
@@ Debug(237) : $oIE = 0 >Error code: 5    Extended code: 0x00000002
--> IE.au3 T3.0-2 Error from function _IEGetObjByName, $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IEAction(focus), $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

Share this post


Link to post
Share on other sites

I am running AutoIt Version: 4.1.0 and I think the _IEAttach failed or something. 

Here is the error code block from this run.

+>15:14:28 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4

+>15:14:28 AU3Check ended.rc:0

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147023174, Browser has been deleted prior to operation.)
--> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
--> IE.au3 T3.0-2 Error from function _IEAttach, $_IESTATUS_InvalidValue (Invalid Mode Specified)
@@ Debug(237) : $oIE = 0
>Error code: 5    Extended code: 0x00000002

--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
--> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IEGetObjByName, $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IEAction(focus), $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

 +>15:18:03 AutoIt3.exe ended.rc:0
+>15:18:03 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 216.2

 

Here is the code I tried:

#include <IE.au3> ; Allows Internet Explorer functions (I forgot to include in the code paste. It is in my code though)

$oIE = _IECreate("https://...")

; Wait for a browser page load to complete
_IELoadWait($oIE)
Sleep(7000)

; Attach to a browser control embedded in another window
$oIE = _IEAttach("A Window Title", "")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & '    Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console
MsgBox($MB_SYSTEMMODAL, "", '@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & '    Extended code: 0x' & Hex(@extended) & @CRLF)

$oIE = _IEAttach("AutoIt")
MsgBox($MB_SYSTEMMODAL, "The URL", _IEPropertyGet($oIE, "locationurl"))


; Store the field names where the important data will be sent
Local $nWorkOrderB   = _IEGetObjByName($oIE, "toolactions_INSERT-tbb_image")

;_IEImgClick($oIE, "toolactions_INSERT-tbb_image", "id")
Sleep(1000)
_IEAction($nWorkOrderB, "focus")
_IEAction($nWorkOrderB, "click")

and Yes, I am using an actual URL do not let the ... fool you. 

Edited by nooneclose

Share this post


Link to post
Share on other sites

One question: Whether this  webpage contain FRAMES ?


Signature beginning:   Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  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 APIErrorLog.au3 UDF - A logging Library *

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 *

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

"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: 2021-01-03

Share this post


Link to post
Share on other sites

how about this instead of leaving the URL out and you in the dark. I just give you the test site so you can see for your self what I am trying to click on. 

https://www-01.ibm.com/support/docview.wss?uid=ibm10729160

click on that link. then click on Maximo Asset Management link (7.6.1)

Then use the username: "maximo" password: "maxpass1"

Then in the bottom left corner hover on "work orders" and click work order tracking

Then you will see the page where I am trying to have Autoit click on the blue circle with a white cross in the middle which is the same as my piece of paper with a blue # (aka the new work order button)

@mLipok I do not know if it has frames or not. Please see for yourself 

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MiKa666
      Hi all,
      I'm developing a tool for exploratively testing another software. For that I wanna cover all the GUI functionality from that software and verify everything works as intended. But now I've a problem which I couldnt solve so far.
      One thing that software I'm testing does, is to load up either a single picture or a series of pictures. Depending on how much pictures got loaded, further actions will be proceeded...
      This loaded pictures are schon within a ToolbarWindow and they're clickable. What I need to know is, how much pictures are in this ToolbarWindow...
      Can anybody provide me a tip on how to achive this?
      Would be amazing!!
      BR,
      Mic
    • By meety
      Hello!
      wingettext function can get the text content of the IE browser page, but the text content of the page cannot be obtained in the chrome browser? What should I do?
    • By DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      Original:
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • By Deshanur
      Am trying to automate injecting credential on the login form for all kind of Web application for IE. I know how to identify the form name by viewing the source code and using the method - _IEFormGetObjByName($ie, $form_Name).
      I would like to know how to identify or get the form object for the web app where there is no form name tag for example below, for the is I have used - _IEFormGetCollection($ie, 0) to get the form object.
      My Question is does it work for all kind of application "_IEFormGetCollection($ie, 0)" how to identify Index value? is it always 0? is there any better solution?
      The final solution am looking for is find out form object, get the username, password field and inject credential and submit the form.
      How to find out index value? for the forms which does not have form name field.
      $login_form = _IEFormGetCollection($ie, 0) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}") OR This works fine if the form has form name. $login_form = _IEFormGetObjByName($ie, $form_Name) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}")
    • By JuanFelipe
      Hello guys!
      I have a problem with a script, in the past I made a program and it worked perfect, I recently used it again and it already stands still in one step, the problem is a Javascript event that changed but now I cannot execute it.
       
      <td colspan="2" align="center"><input type="button" id="Buscar" name="Buscar" value="Buscar" onclick="javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');" class="boton"></td>  
      Previously I used this code and it worked, but now it does nothing
      $botonconsulta = _IEGetObjByName($oIE,"Buscar") _IEAction($botonconsulta, 'click') _IELoadWait($oIE)  
      Now I have tried the following codes but none works.
       
      ;==================== 1 _IEHeadInsertEventScript($oIE, "document", "onclick", "javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');") ControlClick("SUPER CELAC", "", "[CLASS:Internet Explorer_Server; INSTANCE:1]") _IELoadWait($oIE) ;==================== 2 $forma = $oIE.document.obtenercasosPersonaPorDocumento $oIE.Navigate("JavaScript:enviarForma("&$forma&",""0"");") _IELoadWait($oIE) ;==================== 3 $boton = _IEGetObjById($oIE, "Buscar") $boton.document.parentwindow.execScript("enviarForma(document.obtenercasosPersonaPorDocumento,'0');", "javascript") I hope you can guide me, because I think the error is in the parameters that the javascript function receives but I don't know how to send it, here I leave the first part of the JavaScript function.
      function enviarForma(frm,tipoForma){ var bExisteDatoConsulta = false; var bError=true; var mensajeError=""; switch (tipoForma) { //--Forma documento case "0": if (validar_campo_no_vacio_no_print(frm.numeroDocumento)) { if (!isNum(frm.numeroDocumento.value)) { bError = false; mensajeError += "El número de documento debe ser un valor numérico\n"; } bExisteDatoConsulta = true; } else { mensajeError += "Debe digitar un número de documento\n"; } break;  Thanks!
×
×
  • Create New...