+ Reply to Thread
Results 1 to 44 of 44

GetElementById vba issue

  1. #1
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    GetElementById vba issue

    Hi Guys...

    Have come along way with web scraping but am stuck on one certain element...Can anyone perhaps assist...
    In below images the highlighted yellow Dropdown has 4 selections
    I require selection 4
    below is some of the code I have tried...None works...
    Image1.png
    Image2.png
    Image3.png

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by Sintek; 02-27-2018 at 07:40 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

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

    Re: GetElementsById vba issue

    getElementsByName returns a collection of elements, to work with a specific element in the collection you need to specify which one you want.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementsById vba issue

    Hi Norie

    Tx for your response... How would I establish that from the html inspection image above...

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

    Re: GetElementsById vba issue

    You should be using getElementById. not getElementsByName

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementsById vba issue

    So this code errors as Run-time error 424 Object required
    Please Login or Register  to view this content.
    Really having a hard time grasping this stuff man...

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

    Re: GetElementById vba issue

    That implies that the element is not in the page when the code runs. Has the page finished loading? Is the select in an iframe?

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Thanks for sticking by me Kyle123

    Page has finished loading...Herewith page screenshot and 2 level element html
    Image1.png

    Image3.png

    Above is For Report Fields


    Image2.png

    Above is for Performance
    Last edited by Sintek; 02-27-2018 at 10:23 AM.

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

    Re: GetElementById vba issue

    How do you know it's finished loading, what's your code?

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    I am stepping through code...not running so I wait for all screens to finish loading...

    Please Login or Register  to view this content.

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

    Re: GetElementById vba issue

    This:
    Please Login or Register  to view this content.
    Should be:
    Please Login or Register  to view this content.
    As far as I can tell

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Have tried that as per Post 5

    Untitled.png

  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 vba issue

    And when you run that line does the select with that ID exist in the page?

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Doesn't get that far as it errors...Kyle do you know of any links I can check out to try and understand this stuff...

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

    Re: GetElementById vba issue

    Sorry, nothing I can recommend, I don't use IE for we scraping, it's a bit slow and icky.

    Where does it error then?

  15. #15
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    So this code errors as Run-time error 424 Object required


    Please Login or Register  to view this content.

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

    Re: GetElementById vba issue

    As I said, that indicates that the item isn't in the page, but unless you post the actual html at that point and not a screenshot of the select (which is useless), it's impossible to say. Also, for things like this you should be using the inspector in IE, not firefox, it's possible that things are set to render differently in different browsers.

    Is it there in the IE developer tools at the point the code is running?

  17. #17
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    IE does not allow me to inspect that element even when I use Firebug.

    unless you post the actual html
    How would one do this?

  18. #18
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: GetElementById vba issue

    sintek, have you tried adding reference to HTML Object Library & Internet Controls?

    I'd recommend doing this. There are some oddities in these libraries, that getElement(s)Byxxx method misbehaves.
    Also, it's good idea to declare objects explicitly in HTML as single element can have multiple type of objects belonging to it (ex. childnode, Tag etc).

    But if possible, using Developer Tool, trace what request is sent to sever when you makes selections and submit.
    Then use xmlhttp or winhttp to send "GET" or "POST" request to the sever with appropriate headers and request string.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  19. #19
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Hi CK76

    Both are ticked...This is the 18th and second last step in my report extraction and darn I'm stuck...
    But if possible, using Developer Tool, trace what request is sent to sever when you makes selections and submit.
    Then use xmlhttp or winhttp to send "GET" or "POST" request to the sever with appropriate headers and request string.
    This is Greek to me lol...

    Looking at the images of the inspect element is there anything that stands out that has to be set prior to
    Please Login or Register  to view this content.
    Last edited by Sintek; 02-27-2018 at 01:55 PM.

  20. #20
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Freak-in amazing......10 hours and i still can't get one line of code to work WTF

  21. #21
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Something that might be important????
    In below code, the red part opens another page...
    Please Login or Register  to view this content.
    End Sub

  22. #22
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    In that case wait until the page is loaded. So after the obj.Click add the following lines...

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  23. #23
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    Or this...
    Please Login or Register  to view this content.

  24. #24
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Hi sktneer

    Thanks for joining in...I am stepping through the code and am waiting for page to fully load before next step...

  25. #25
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    After the new page is loaded completely, the element with id "lblCustomReportBuilder" exists as per the html document?

  26. #26
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Yes it does

    Untitled.png

  27. #27
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    The highlighted line is h1 tag with id title not the id lblCustomReportBuilder.
    What I am missing here?

  28. #28
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    I see. The element you are interested in has the id 'PerformancePeriodStepType" but that's not visible either in the image you posted.

  29. #29
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    I really don't know sob sob sob

    This is Main Page prior to clicking Report Builder
    Main page.png

    This is the inspect element of Report Builder button
    ButtonClick.png

    This is Next Page that opens...
    Image1.png

    This is inspect element of dropdown box
    Button inspectElement.png

  30. #30
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: GetElementById vba issue

    In below code, the red part opens another page...
    Does it just navigate to new page, or does it open another page in new tab/window?

    If it opens in another window. You'd need to use Shell.Application to specify the window to use.
    See link for example I did in another forum.
    https://chandoo.org/forum/threads/ho...6/#post-222660

    Check also if site uses iframe(s). If it does, you'll need to specify which iframe you are accessing.
    Something like...
    Please Login or Register  to view this content.

  31. #31
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Does it just navigate to new page, or does it open another page in new tab/window?
    Opens another page in a new tab window...Not a website it is an server that allows for report statistical information extraction...

  32. #32
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Same site two different pages...It is basically a form that opens up...
    https://analytics.financialexpress.net/Default.aspx#
    https://analytics.financialexpress.n...leBuilder.aspx

    Have to step out..Will carry on trying again tomorrow...I am certain that it is something so simple....


    @ Norie, Kyle123, sktneer, CK76
    Thanks for all your input so far guys...
    Last edited by Sintek; 02-27-2018 at 04:18 PM.

  33. #33
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Morning All

    Yesterday was one of those days where i wanted to pull out my hair lol...
    I understand that I need to somehow get access to the pop up page prior to access to the dropdown button...
    This is the inspect element of that pop up page...What can i make use of to set focus to that page?

    PoPUp Form element.png

  34. #34
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    Hi Sintek,

    Sorry! I am not able to help.
    I had a similar issue with the login method on a website where after clicking the Login button, a new popup window popped up for user to fill the username, password and a submit button to login on the website. And then after filling the username and password, I was unable to click the submit button as it was greyed out after filling the inpuboxes programmatically. In that case, the address of the IE also changed and what I did then I used the changed address for IE to navigate and accessed the html document. See if something similar happens in your case after popup window appears.

  35. #35
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Morning sktneer

    That is definitely the case...I need to set focus to the new pop up window before getting access to the element id...
    Found some code which is supposed to do this but having difficulty getting it to work as it renders "" results
    Please Login or Register  to view this content.

  36. #36
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    What's the IE address when the popup window appears? Is it different from the base url?

  37. #37
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Yep...As follows:
    analytics.financialexpress.net/Default.aspx
    analytics.financialexpress.net/CustomTableBuilder.aspx

  38. #38
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    So instead of finding and clicking the obj which opens popup window, can you try .Navigate "analytics.financialexpress.net/CustomTableBuilder.aspx" and then try to find the element with the desired id? Just a thought.

  39. #39
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Was thinking that could work but unfortunately doesn't *** the code navigates back to Login screen...Seems one can only get that form to popup once logged in...

  40. #40
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    I meant you need to use .Navigate twice, once for login and another for popup window. Did you try like that?

    i.e. replace the following lines (which I guess opens the popup window)
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  41. #41
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Yep, that is what I did... It unfortunately navigated to the login screen..

  42. #42
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Alrighty then... Think we getting somewhere...This worked perfectly the first two times but then an error came up after 3rd time testing...
    Please Login or Register  to view this content.
    Error_Msg.png

  43. #43
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: GetElementById vba issue

    Hey guys...The original problem was solved, so i am gonna mark as such...Thank you all once again...
    I will open a new thread with error...

  44. #44
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: GetElementById vba issue

    You're welcome Sintek! Glad your original issue got resolved.
    Thanks for the rep.

+ 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. Replies: 7
    Last Post: 12-15-2017, 12:14 AM
  2. Use excel VBA to access website - error 424 on getElementsbyID
    By twanbiz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2016, 10:06 AM
  3. Ability to select multiple .values under .getelementsbyid
    By Al_O_L in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2014, 05:19 PM
  4. [SOLVED] Insert shift down issue macro issue
    By CC64 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2012, 10:57 PM
  5. how to loop in general and then apply .getelementsbyID
    By jayinthe813 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2012, 08:45 PM
  6. Issue with X axis values NOT graphing on Scatter graph and issue with Labels
    By lmausolf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2012, 07:20 AM
  7. [SOLVED] Issue - Attachment issue - by Simon Lloyd
    By Vaibhav in forum Suggestions for Improvement
    Replies: 16
    Last Post: 03-16-2012, 06:56 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