+ Reply to Thread
Results 1 to 15 of 15

getelementbyid with duplicate ID's on Page

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    getelementbyid with duplicate ID's on Page

    I have an excel spreadsheet that uses the document.getelementbyid("Place id here"). I think it is throwing an error because on the page I am trying to grab information from there are two id's that are the exact same. What can be done to keep this from erroring out?

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

    Re: getelementbyid with duplicate ID's on Page

    I think IDs are unique, so it can not be duplicate.

  3. #3
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    I have an example of a page with duplicates. There are two elements with the id "dealTitleLink". The page is http://www.amazon.com/gp/goldbox

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

    Re: getelementbyid with duplicate ID's on Page

    When I search on the source code, dealTitleLink returns zero.

  5. #5
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    If you go the the page right click and inspect an element and then search. There are two of them.

  6. #6
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    I don't think it is the duplicate that is throwing this error anymore. I am getting a type mismatch error after this line of code. Set a = ie.Document.getelementbyid("dealTitleLink"). Microsoft says that if there are duplicate id's then it will just return the first one. Any other ideas on what might be causing this?

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: getelementbyid with duplicate ID's on Page

    What's a dimmed as?

  8. #8
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    Here is the code up to that point.
    Sub getDealOfTheDay()
    Dim promoTitle$, promoLink$, a
    
    'inbetween here I have code that opens internet explorer
    
    openPage "http://www.amazon.com/gp/goldbox/", ie
    Set a = ie.Document.getelementbyid("dealTitleLink")
    Last edited by manofcheese; 08-31-2015 at 02:32 PM.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: getelementbyid with duplicate ID's on Page

    Where's the rest of it? Are you sure you've allowed sufficient time for the page to finish loading before trying to get the element?

  10. #10
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    In the rest of the code it loops through to add more time until the whole page has loaded. This was working fine last week and then it just broke when I opened it today. Have there been any microsoft updates recently that might affect this?

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: getelementbyid with duplicate ID's on Page

    It's far more likely that Amazon have changed their page, however without you posting your full code there's very little we can do to help, if you post it, I'm happy to take a look

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: getelementbyid with duplicate ID's on Page

    In fact, I don't have any id of dealTitleLink in that page

  13. #13
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    Example.PNG
    This is what I am able to see

  14. #14
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: getelementbyid with duplicate ID's on Page

    It looks like it is changed in Internet Explorer but in Chrome it is still the same. Any suggestions on how to pull that same data?

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

    Re: getelementbyid with duplicate ID's on Page


    Hi,

    in case of duplicates ID (not often but I yet met several times) in same window or form,
    getElementById returns a collection … So you can separate each one by index as item(0), item(1) …

+ 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. IE.Document.getElementById("ID") not working!
    By excel_drives_crazy in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-11-2018, 10:16 AM
  2. getElementById run-time 13 type mismatch error
    By killerkoz17 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2014, 10:41 PM
  3. [SOLVED] VBA Code x2 i have a code i want to duplicate in another cell on the same page
    By Garbology in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-27-2013, 01:27 AM
  4. Easiest way to add a duplicate page in the same sheet
    By rjbtag52 in forum Excel General
    Replies: 1
    Last Post: 06-04-2013, 04:25 PM
  5. IE.document.getElementByID returns run-time error '91'
    By matt100 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2013, 09:32 PM
  6. problem extracting data from webpage using getelementbyid
    By mwalshe99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2012, 08:57 AM
  7. Duplicate values in Pivot table Page Field dropdown..
    By trippknightly@hotmail.com in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-27-2006, 10:50 PM

Tags for this Thread

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