Get Elements by ID Keeps varying.

  • HTML
    <label id="label303497400" class="label f6" style="top: 4px; left: 0px; width: 112px; height: 17px;" for="x-arid_WIN_2_303497400"> … </label>
    <textarea id="arid_WIN_2_303497400" class="text sr " rows="1" arautoctt="400" arautocak="0" arautocmb="1" arautoc="1" mstyle="2" armenu="HPD:CustomerCIwithoutBusinessService" style="top:0; left:117; width:175; height:21;" maxlen="255" cols="20" wrap="soft"></textarea>


    <textarea id="arid_WIN_2_303497400", ID keeps varying all the time eg : textarea id="arid_WIN_1_303497400" , textarea id="arid_WIN_3_303497400"


    So how to get elements by id.


    Tried below VBA code nothing seems to working.


    Set ie_elecollec = ie_doc.getElementsByTagName("textarea")
    Set ie_elecollec = ie_doc.getElementsByid("_303497400")

    aNotes.Value = Sheets("Sheet1").Range("E6").Value

  • Re: Get Elements by ID Keeps varying.


    ....or


    do a counting loop for 1 to what ever the max might be....


    When you get an error then you exit the loop because there is no more item by that ID.

  • Re: Get Elements by ID Keeps varying.


    If the page has been coded correctly then strict HTML/XHTML would dictate there is only one element with that id - so John_w suggestion should get you the id you require because no other element on the page "should" have the same "id". You can only use an id once in HTML or XHTML - you can use the same class as many times as you want but id is a different story. That being said though it will only cause a failure in validation and problems with associated javascript not necessarily prevent the page from resolving correctly.

    Regards
    [SIZE=3]Anthony
    [/SIZE]&WCF_AMPERSAND[SIZE=3]
    [/SIZE]&WCF_AMPERSAND&WCF_AMPERSAND&WCF_AMPERSAND[SIZE=2]You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.[/SIZE]




  • Re: Get Elements by ID Keeps varying.


    Quote from John_w;700664

    Loop through the collection returned by getElementsByTagName("textarea"), and use the Like operator to look for the element id matching "arid_WIN_*_303497400".



    Tried No Success, "arid_WIN_*_303497400"

  • Re: Get Elements by ID Keeps varying.


    Quote from iwrk4dedpr;700720

    ....or


    do a counting loop for 1 to what ever the max might be....


    When you get an error then you exit the loop because there is no more item by that ID.


    Tried No Success, "arid_WIN_*_303497400" "*" Varies from 1 to 10.

  • Re: Get Elements by ID Keeps varying.


    No success means?


    The loop didn't throw any errors? Or as suggested there are more than 1 object with the same id and you only got the first item?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!