Jump to content

_IE changing ID of text box


Recommended Posts

Hello guys,

I want script that locate text box on webpage and write text in it, problem is that, that website is changing their ID of text boxes.Problem.thumb.jpg.0ae92b689aeb39dd4b2903

The last few digits of ID(highlighted yellow one) is changing every single time, so i would like to ask if there is way how to solve this. /// It is possible to use only part of ID to localize the text box ?

Thanks

Edited by AnakondaSK
Link to comment
Share on other sites

I asked on this issue on one other forum and no one answered (same situation as here).

I dont know if I am asking wrong or there is no solution for locating text box or button on webpage which is changing part of their ID every single time I open it.

So I would like to ask for closeing this topic, Guess there is no reason for letting it open.

Link to comment
Share on other sites

because you ask the wrong way, every one else is probably too bored to try something for you, if you on the other hand try to read the help file, and then try to come up with something, even if you fail to get it right, you will probably get better results here than just asking the way you did

post the code using the add code <> (in text toolbar) so it is easyer to try someting,(the same goes for example code) you can probably get the changing id buy capturing the inerhtml in to a $variable then use stringbetween "<input etcetcetrcValue_" as the start and '" style=ETCETCETCETCETCETC""></input>' as the end to extract the changing id name then go hit it up with _iegetobjbyID

Link to comment
Share on other sites

It would be easier if you put here this HTML snippet here as a text instead image.

But I would do it in this way:

_Example($oIE)
Func _Example(ByRef $oIE)
    Local $sHTML_DocContents  = _IEDocReadHTML($oIE)
    Local $aHTML_Element = StringRegExp($sHTML_DocContents,'id="(header_processSearchValue_\d+?)"',$STR_REGEXPARRAYGLOBALMATCH )
    if @error Then
        Return SetError(@error, @extended, '')
    Else
        Return SetError(0,0,$aHTML_Element[0])
    EndIf
EndFunc

 

Edited 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 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

You can do through the class name instead of ID using this function:

;===============================================================================
;
; Function Name:    _IEGetObjByClass()
; Description:      Returns an object variable by Class
; Parameter(s):     $o_object   - Object variable of an InternetExplorer.Application, Window or Frame object
;                   $s_Class    - Specifies class of the object you wish to match
;                   $i_index    - Optional: If the class occurs more than once, specify which instance by 0-based index
; Requirement(s):   AutoIt3 V3.2 or higher
; Return Value(s):  On Success  - Returns an object variable pointing to the specified Object
;                   On Failure  - Returns 0 and sets @ERROR
;                   @ERROR      - 0 ($_IEStatus_Success) = No Error
;                               - 3 ($_IEStatus_InvalidDataType) = Invalid Data Type
;                               - 7 ($_IEStatus_NoMatch) = No Match
;                   @Extended   - Contains invalid parameter number
; Author(s):        Bob Anthony (big_daddy)
;
;===============================================================================
;
Func _IEGetObjByClass(ByRef $o_object, $s_Class, $i_index = 0)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEGetObjByClass", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    If Not __IEIsObjType($o_object, "browserdom") Then
        __IEErrorNotify("Error", "_IEGetObjByClass", "$_IEStatus_InvalidObjectType")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    Local $i_found = 0
    ;
    $o_tags = _IETagNameAllGetCollection($o_object)
    For $o_tag In $o_tags
        If String($o_tag.className) = $s_Class Then
            If ($i_found = $i_index) Then
                SetError($_IEStatus_Success)
                Return $o_tag
            Else
                $i_found += 1
            EndIf
        EndIf
    Next
    ;
    __IEErrorNotify("Warning", "_IEGetObjByClass", "$_IEStatus_NoMatch", $s_Class)
    SetError($_IEStatus_NoMatch, 2)
    Return 0
EndFunc   ;==>_IEGetObjByClass

 

Link to comment
Share on other sites

Thank you very much for all answeres you all helped me a lot especially this one:

It would be easier if you put here this HTML snippet here as a text instead image.

But I would do it in this way:

_Example($oIE)
Func _Example(ByRef $oIE)
    Local $sHTML_DocContents  = _IEDocReadHTML($oIE)
    Local $aHTML_Element = StringRegExp($sHTML_DocContents,'id="(header_processSearchValue_\d+?)"',$STR_REGEXPARRAYGLOBALMATCH )
    if @error Then
        Return SetError(@error, @extended, '')
    Else
        Return SetError(0,0,$aHTML_Element[0])
    EndIf
EndFunc

 

Now I am able to track ID even if its it changing. So thank you one more time !

If I can ask you I have one more problem. I need to click on button, I have for sure the right ID of it but my code its not working, not sure why,I check id multiple times and I am not able find the problem why.

HotKeySet("{ESC}", "Terminate")
Opt("WinTitleMatchMode", 2)
Opt("MouseCoordMode",0)


#include <IE.au3>


Call ("CREW") ;call function

Func CREW()
    Global $oIE = _IECreate("www.nameofweb.com",1) ;open then website
    Local $sHTML_DocContents  = _IEDocReadHTML($oIE)
    Local $aHTML_Element = StringRegExp($sHTML_DocContents,'mainProperties_assignedTo_clear_\d+',1) 
    If @error == 0 Then
         Local $WOW = $aHTML_Element[0] ;now I have right ID of button (I check id through MSgBox and its the rifght one)
     EndIf

Local $id = _IEGetObjById ($oIE, $WOW)
    _IEAction ($id, "click") ; Calling for click but its not working, dont know why
    _IELoadWait ($oIE)
    Sleep(2000)
EndFunc


Func Terminate()
Exit 0
EndFunc

Thank you for your time and help I really appreciate it!

Link to comment
Share on other sites

;now I have right ID of button (I check id through MSgBox and its the rifght one)

try to spot the problem, all i can think of atm is check if $id is an object, try with IsObj($id) try ConsoleWrite('$id='&IsObj($id)&@lf) or use msgbox. if the result is 0 then its not an object, and you'll have to spot the object or element above that one before you get to that one

Link to comment
Share on other sites

try to spot the problem, all i can think of atm is check if $id is an object, try with IsObj($id) try ConsoleWrite('$id='&IsObj($id)&@lf) or use msgbox. if the result is 0 then its not an object, and you'll have to spot the object or element above that one before you get to that one

I add this in my code as you recommended:

if not IsObj($id) Then
        MsgBox(0,"Error", "No object")
    else
        MsgBox(0, "Error","Is object")
    EndIf

And result in MsgBox was "Is Object", so now we know its object but still there is a question why my code dont want to click on it :/

Link to comment
Share on other sites

Consolewrite id.html or id.name ir id.innerHTML to see if you have the right object. Also get an array of all buttons to see if you have the right one.

Look I made this super easy script for filling username and password then clicking on button "Prihlás" on public page.

#include <IE.au3>

Global $oIE = _IECreate("http://www.zoznam.sk/",1)

$username = _IEGetObjByName($oIE, "login")
$password = _IEGetObjByName($oIE, "password")
$oForm = _IEGetObjByName ($oIE, "prihlas")



_IEFormElementSetValue ($username, "123456")
_IEFormElementSetValue ($password, "654321")

Sleep(1000)
_IEAction($oForm, "click")

What it does...it fill username and password but does not click on button. Its possible that something is blocking my script ? some IE interface or something ?

Thank for help

 

Edited by AnakondaSK
Link to comment
Share on other sites

you write a super simple script with confusing variable names

$oForm gives a suggestion to click on a form and not on a buttion so $oButton seems more logical.
anyway with any object/element searching you somehow should validate if you have the right object thats what I tried to say

so consolewrite any informational property from http://www.w3schools.com/jsref/dom_obj_all.asp 

consolewrite($oForm.visible)

consolewrite($oForm.className)

consolewrite($oForm.clientTop)

consolewrite($oForm.innerHTML)

And I would not be surprised if you have to write

_IEAction($oForm[0],"click") or $oForm[0].click() or $oForm.click()

Link to comment
Share on other sites

I would like to thank all for help. I finally find out where the problem was. I was testing my simple script at home and everything works fine, so I asked one IT guy in my company and he said that they have restriction in settings in case of scripts.

So I can only fill text to text-boxes but I am unable to click on button by using_IE functions. I guess there is only option for me and that is to use mouseclick.

So thank you all for help once more ! :)

Link to comment
Share on other sites

i would encourage you to install a debugbar, it will help you a lot with IE stuff, I usually use the firebug one on firefox because i understand it better than the others and don't give up so easily could you post your complete script that did work up until mouse click?
here is what i was playing with, and it clicks the button

 

#include <IE.au3>

Local $oIE = _IECreate("http://www.zoznam.sk/",1,1,1)
$form=_IEGetObjByName($oIE, "login-form")
;~ ConsoleWrite($form.innerhtml)
;~ ConsoleWrite($form.id&@CRLF)

$div = _IETagNameGetCollection($form,'input')
for $items in $div
    ConsoleWrite("innerhtml="&$items.innerhtml&@CRLF)
    ConsoleWrite("innertext="&$items.innertext&@CRLF)
    ConsoleWrite("tagname="&$items.tagname&@CRLF)
    ConsoleWrite("id="&$items.id&@CRLF)
    ConsoleWrite("name="&$items.name&@CRLF)
    ConsoleWrite("value="&$items.value&@CRLF)
    ConsoleWrite('------------------------------------------------------------------------------------------------------------------------------------------------------------'&@CRLF)

;   my firt try failed
;~  if $items.id = 'mailUsername' Then
;~      $items.innertext='USERNAME'
;~      ConsoleWrite($items.innerhtml&@CRLF)
;~  EndIf

    ;this one worked
    if $items.id = 'loginid' Then
        $items.innertext='USERNAME'
;~      ConsoleWrite($items.innerhtml&@CRLF)
    EndIf

    if $items.id = 'passwordid' Then
        $items.innertext='PASSWORD'
;~      ConsoleWrite($items.innerhtml&@CRLF)
    EndIf

    ;the button to click, in this case the button show up after user and pass are set
    ;so there is no problem clicking in the same 'for in' loop
    if $items.id = 'prihlas' Then
        $items.click()
    EndIf
Next

 

Link to comment
Share on other sites

Try a javascript in your addressbar like:

Javascript:document.getelementbyid('yourid').click();void(0);

I tried but does not work :/

i would encourage you to install a debugbar, it will help you a lot with IE stuff, I usually use the firebug one on firefox because i understand it better than the others and don't give up so easily could you post your complete script that did work up until mouse click?
here is what i was playing with, and it clicks the button

 

#include <IE.au3>

Local $oIE = _IECreate("http://www.zoznam.sk/",1,1,1)
$form=_IEGetObjByName($oIE, "login-form")
;~ ConsoleWrite($form.innerhtml)
;~ ConsoleWrite($form.id&@CRLF)

$div = _IETagNameGetCollection($form,'input')
for $items in $div
    ConsoleWrite("innerhtml="&$items.innerhtml&@CRLF)
    ConsoleWrite("innertext="&$items.innertext&@CRLF)
    ConsoleWrite("tagname="&$items.tagname&@CRLF)
    ConsoleWrite("id="&$items.id&@CRLF)
    ConsoleWrite("name="&$items.name&@CRLF)
    ConsoleWrite("value="&$items.value&@CRLF)
    ConsoleWrite('------------------------------------------------------------------------------------------------------------------------------------------------------------'&@CRLF)

;   my firt try failed
;~  if $items.id = 'mailUsername' Then
;~      $items.innertext='USERNAME'
;~      ConsoleWrite($items.innerhtml&@CRLF)
;~  EndIf

    ;this one worked
    if $items.id = 'loginid' Then
        $items.innertext='USERNAME'
;~      ConsoleWrite($items.innerhtml&@CRLF)
    EndIf

    if $items.id = 'passwordid' Then
        $items.innertext='PASSWORD'
;~      ConsoleWrite($items.innerhtml&@CRLF)
    EndIf

    ;the button to click, in this case the button show up after user and pass are set
    ;so there is no problem clicking in the same 'for in' loop
    if $items.id = 'prihlas' Then
        $items.click()
    EndIf
Next

 

Your script is working perfect on my Home pc but not ony my Working PC, as I said before, in company where I work there are restrictions in settings as I find out, so sadly all scripts I tried are not working properly. (For example your script just open IE with website and then it ends).

No matter what, I would like to thank all people that helped me, I learned a lot in these few days! :)

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

×
×
  • Create New...