Jump to content
AnakondaSK

_IE changing ID of text box

Recommended Posts

AnakondaSK

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

Share this post


Link to post
Share on other sites
AnakondaSK

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.

Share this post


Link to post
Share on other sites
jvds

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

Share this post


Link to post
Share on other sites
mLipok

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
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 *

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 * 

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

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 *

"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: 2018-10-31

Share this post


Link to post
Share on other sites
J2TeaM

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

 

  • Like 1

Share this post


Link to post
Share on other sites
AnakondaSK

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!

Share this post


Link to post
Share on other sites
jvds
;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

Share this post


Link to post
Share on other sites
AnakondaSK

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 :/

Share this post


Link to post
Share on other sites
AnakondaSK

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

Share this post


Link to post
Share on other sites
junkew

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()

Share this post


Link to post
Share on other sites
AnakondaSK

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 ! :)

Share this post


Link to post
Share on other sites
jvds

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

 

Share this post


Link to post
Share on other sites
AnakondaSK

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! :)

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

  • Similar Content

    • IAMK
      By IAMK
      If you press the "Login" button in the top-left of https://www.showroom-live.com/, it creates a popup in which you press "Login with Twitter ID", which then opens a new window with an "Authorize app" button.
      None of these 3 buttons have a Name or ID, so how do I click on them, because _IEGetObjByName / _IEGetObjByID will not work.
      Here are the sources of the 3 buttons:
      ;Login button. ;<a onclick="showLoginDialog();" href="javascript:void(0);">Login</a> ;Twitter button (Note that I am already signed into Twitter and just need to Authorize it). ;<a class="btn-twitter btn-sky-blue submit fs-b5" onclick="window.open('/social/twitter/redirect_authorize_url?login=1&from_browser=1', 'twitter', 'width=500,height=400,menubar=yes,status=yes,scrollbars=yes');" href="javascript:void(0);">Login with Twitter ID</a> ;Popup window appears. ;<input class="submit button selected" id="allow" type="submit" value="Authorize app"> I have also tried:
      Local $oLinks = _IETagNameGetCollection($ie, "a") For $oLink In $oLinks If $oLink.InnerText = "showLoginDialog()" Then _IEAction($oLink, "Click") ExitLoop EndIf Next I've even tried adding "showLoginDialog()" and "javascript:void(0)" to the end of the URL, but as expected, that wouldn't work either.
      My goal is something like this:
      #include <IE.au3> Local $ie = _IECreate("https://www.showroom-live.com/onlive") _IELoadWait($ie) Local $originalHandle = $ie ;===Functions========================================================== Func login() ;Source: <a onclick="showLoginDialog();" href="javascript:void(0);">Login</a> _IEAction(ABOVESOURCE, "Click") ;Source: <a class="btn-twitter btn-sky-blue submit fs-b5" onclick="window.open('/social/twitter/redirect_authorize_url?login=1&amp;from_browser=1', 'twitter', 'width=500,height=400,menubar=yes,status=yes,scrollbars=yes');" href="javascript:void(0);">Login with Twitter ID</a> _IEAction(ABOVESOURCE, "Click") ;New window appears for Twitter sign in, but the URL is locked. ;Source: <input class="submit button selected" id="allow" type="submit" value="Authorize app"> _IEAttach($ie, ABOVEHANDLE) ;How do I get the handle of the new window from above? _IEAction(ABOVESOURCE, "Click") _IEAttach($ie, $originalHandle) EndFunc ;====================================================================== ;===Code=============================================================== login() ;======================================================================  
      Thank you in advance.
    • faustf
      By faustf
      hi guys how is possible set a speed of  all function _Ie ?? 
    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I'm trying to create a webscrape script using AutoIt.  A non-profit I'm involved with is using GroupSpaces.com and there is no notification to the group when someone posts a new topic to the forum.  I'm including IE.au3

      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <String.au3>
      ; Open Groupspaces.com
      Global $oIE = _IECreate ("http://www.groupspaces.com")
      _IENavigate($oIE,"http://groupspaces.com/MyCrazyTest/forum/")
      ;Grab all the links on the Forum page
      Global $oLinksCategoryPage = _IELinkGetCollection($oIE)
      For $oLink In $oLinksCategoryPage
          Local $oLinkHRef = $oLink.href
          If StringInStr($oLinkHRef,"forum_id") Then
              ;This is a category. Click into it.
              _IENavigate($oIE,$oLinkHRef)
      Sleep(3)
              ;Back out to Category List
              _IEAction($oIE,"back")
          EndIf
      Next
      _IEQuit($oIE)
    • AutoBert
      By AutoBert
      I have a NDIS based Internet sharing device. I got info about my balance inquiry by clicking a button, it's sending ussd *101# to my provider. This was ok in past but no i have changed provider, all other functions are ok, but new provider uses *100# as valid ussd for geting balance inquiry. So i used 
      #include <IE.au3> $oIE=_IECreate('http://192.168.8.1/html/ussd.html') $sHTML=_IEDocReadHTML($oIE) $sHTML=StringReplace($sHTML,'101#','100#') _IEDocWriteHTML($oIE,$sHTML) to get it. But with this script i can't get the info. It replaces correct in 
      <div id="fun_balanceInquiry" style="display: block;"> <div class="ussd_extend_border"><p><label id="balance_inquiry_description0">Auf Guthaben drücken, um Informationen über Ihr Guthaben zu erhalten.</label></p> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tbody><tr><td height="40" class="cls_ussd_label_BalanceInquiry_action"> <label id="balance_inquiry_result0"></label></td> <td class="align_right" id="balance_inquiry_action0"><span class="button_wrapper" id="#BalanceInquiry0" onclick="javascript:ussd_sendCommand('BalanceInquiry0','*101#','CodeType', 'undefined');return false;"><span class="button_left"><span class="button_right"><span class="button_center">Guthaben</span></span></span></span></td> </tr></tbody></table></div></div> <div id="fun_charge" style="display: none;"> </div> but it seems this included script:
      <script src="../js/ussd.js" type="text/javascript"></script> is called. In DOM Explorer i see:
      function onclick(event) { javascript:ussd_sendCommand('BalanceInquiry0','*101#','CodeType', 'undefined');return false; } but i can't write a changed ussd.js back to my internet stick.
      So my question is how can i change htmlcode in a way calling function onclick with new ussd command?  
    • avidovi
      By avidovi
      Hello Friends,
      I need your advise automating Facebook search project.
      I need to enter a string in a search input box, the inspect element shows me this code:
      <input name="query" class="inputtext" aria-required="true" aria-label="Search" required="1" type="text" maxlength="100" placeholder="Search this group" value="" autocomplete="off"> How to treat it? as a form? as an IE object?
      Really appreciating your help.

×