AnakondaSK

_IE changing ID of text box

15 posts in this topic

#1 ·  Posted (edited)

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



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

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

#4 ·  Posted (edited)

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 *
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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer 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 * Best coding practices * 

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

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: 2017-06-04

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
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 :/

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

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

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

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

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

    • 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.

    • onlineth
      By onlineth
      Hello, I believe I have come across a bug in the _IE library. I am trying to make a script that will automatically fill's in data for a restore script for a WP site. It's called Importbuddy by IThemes and it is one of the best, if not the best, backup restore plugins for WordPress. The problem that I am having is once it is on the first step of the script, filling in the password and clicking next, it redirects me to the index.php file and when I keep trying to return to the importbuddy.php file, it keeps redirecting back to the index file. Here is the code I am using, 
      _$o = _IECreate() _IENavigate($o, [url of ImportBuddy]) _IELoadWait($o, 2000) $step0 = _IEGetObjByName($o, "password");Password feild _IEFormElementSetValue($step0, "pass");Password of Importbuddy $Step0submit = _IEGetObjByName($o, "submit") _IEAction($Step0submit, "click") _IELoadWait($o, 2000) ;Goes to index.html, not the next step of the importbuddy Here is a link to the importbuddy.php file,   http://bit.ly/1H9YZNb
      Please only use this file for testing, it is part of a commercial product by IThemes 

      To keep this simple, just install a program like XAMPP to view the file. Also, the password is "pass"

      Does anyone have any ideas why this isn't working? 

      As always, Thanks for your help 

      Thomas 
    • Wolfiesaxah
      By Wolfiesaxah
      Hi guys, I need help as I have worked for more than 18 hours in trying to get this resolved but couldn't. There's a registration page that has an iframe and I need to put a check on the checkbox inside that iframe. The iframe's content is pointing to external source.
       
      Could anybody please share a complete simple _IE code to put a check on any of the checkbox in that page so I can analyze it and post my solution here? I am having trouble understanding the syntax of AutoIt. I tried this for hours and couldn't get it to work. The checkbox ID is showing as NOMATCH in AutoIt error report so I thought I had to reference the iFrame first but the iFrame too shows as NOMATCH when they are both sitting there.