+ Reply to Thread
Results 1 to 16 of 16

Control Internet Explorer: Multiple Elements with Same ID

  1. #1
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Control Internet Explorer: Multiple Elements with Same ID

    Dear all

    I've become fairly confident accessing/controlling IE through code, but I have now come across a situation where the source code has the same ID for multiple fields.

    There are a lot if fields, but here are two from the code

    input name="D080999005999"
    id="entry"

    input name="D185999999999"
    id="entry"

    Using
    Please Login or Register  to view this content.
    addresses only the first element with this ID. How can I get to populate the values in the other elements, having the same ID

    Thanks
    FD

    PS: I tried using HTML Tags, but the page returns a firewall warning

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Control Internet Explorer: Multiple Elements with Same ID


    Hi !

    That should not be an issue just by following Document Object Model of the webpage or parsing webpage code …

  3. #3
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    HI Marc

    Could you help me with the code?

    Thx

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Control Internet Explorer: Multiple Elements with Same ID


    Just inspect desired elements with your webbrowser inner inspector tool
    to see if parents elements have an id …

    Just follow webpage object model
    or if data are within initial webpage code, just parse text with VBA text functions (at beginner level) …

  5. #5
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Hi Marc

    Could you give me en example
    I see that parent structure is as follows
    -WGT0
    --label
    ---entry

    and in the second element
    -WGT1
    --label
    ---entry

    How is this addressed in VBA

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Control Internet Explorer: Multiple Elements with Same ID

    FallingDown,
    According to CSS' rules, an ID should be unique, but I have seen some sites duplicating IDS, as this appears to be in your case.
    I do not know if an ID collection exist, but there are collections for Tag names and thus you can use an array to locate a position of an element within the collection.
    You could try, but I doubt if it works.
    ie.document.getElementById("entry")(0) = "My Text" ' First item in the collection
    ie.document.getElementById("entry")(1) = "My Text"

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Have you tried using the name attribute to identify the element(s) you want?
    If posting code please use code tags, see here.

  8. #8
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    @AB33 right - it's also the first time I've seen this. Pretty annoying!
    I actually tried your suggestion prior to posting the thread, though I am wondering if I can count the number of IDs, and then loop through?

    @Norie: Tried that (getElementByName and getElementByTagName)

    Any other idea?
    I would also already help if I could move/jump fields with "TAB". How would I achieve that?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Control Internet Explorer: Multiple Elements with Same ID

    You could set it as an object and see if it returns a value.

    MyTest as object,i as long

    MyTest =ie.document.getElementById("entry")

    I=MyTest.length

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Did you try getElementsByName?

  11. #11
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    @AB33 - no, unfortunately it does not return a value

    @Norie: Yes, I did
    Please Login or Register  to view this content.
    it ends in "Run-time error '438' - Object doesn't support this property or method

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Control Internet Explorer: Multiple Elements with Same ID


    Yes classic typo error, you forgot the s !

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Sorry, not seeing the 's' here.

    Please Login or Register  to view this content.
    Also if you are using something like getElementsByName it will return a collection of elements.

  14. #14
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Hi everyone

    Even with

    Please Login or Register  to view this content.
    it ends in "Run-time error '438' - Object doesn't support this property or method"

  15. #15
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Figured it out...
    has to be
    Please Login or Register  to view this content.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Control Internet Explorer: Multiple Elements with Same ID

    Oops, sorry about that - I should listen to myself.

    getElementsByName returns a collection so you need to specify which item in the collection you want.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem in accessing elements in Internet Explorer
    By Geetha Gupta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2016, 09:07 AM
  2. Need to control Internet Explorer/Firefox
    By vlookup. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2015, 11:31 AM
  3. Javascript control (I think) in Internet Explorer Automation from VBA
    By bluphoto in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-18-2014, 11:54 AM
  4. Use VBA to control Internet Explorer
    By Verbamore in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-17-2014, 05:50 PM
  5. internet explorer control click
    By tomro1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2014, 12:11 PM
  6. Can Excel control Internet Explorer using VBA?
    By simpleonline1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-01-2012, 10:39 PM
  7. Using Macros for Internet Explorer Control
    By PaulAS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-08-2010, 03:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1