+ Reply to Thread
Results 1 to 22 of 22

IE.Document.getElementById("ID") not working!

  1. #1
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    IE.Document.getElementById("ID") not working!

    I am trying to automate Internet Explorer using vba.

    1. I connect to www.google.com (this works fine)
    ... commands :
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate ("http://www.google.com")


    2. I try to select the google search box and to type in "Searchstring" (this does not work)
    ... command:
    IE.Document.getElementById("lst-ib").Value = "Searchstring"


    ... For some reason the command "getElementById" does not work ... neither on google nor on any other website I tried ... but the command is correct ... I copied it directly from a youtube video ....

    What is going on here? Help would be much appreciated!

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

    Re: IE.Document.getElementById("ID") not working!

    You need to set it as an object

    Please Login or Register  to view this content.
    Last edited by AB33; 04-09-2015 at 01:22 PM.

  3. #3
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Thank you for your reply ...
    I had also tried the following code:
    Dim a As Object
    Set a = IE.Document.getElementById("lst-ib")
    a.Value = "Searchstring"

    This didn't work either (and according to the youtube video I watched, setting it as an object is not necessary either ... in the video it just worked with the following command: IE.Document.getElementById("ID").Value = "string")

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

    Re: IE.Document.getElementById("ID") not working!

    Could you tell me where is the link?
    Follow-up lines

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Hi AB33,

    here's the link to the video:

    https://www.youtube.com/watch?v=q7aa76YFFW8

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

    Re: IE.Document.getElementById("ID") not working!

    Not all HTML coding or sites are the same. In Google case, you have a form, so you need to give a value to the form and then submit it.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: IE.Document.getElementById("ID") not working!

    Hello excel_drives_crazy,

    This works...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  8. #8
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Hallo Leith Ross,

    your code created an error message:

    "Method 'Busy' of object 'IWebBrowser2' failed"

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: IE.Document.getElementById("ID") not working!

    Hello excel_drives_crazy,

    The code works on my XP andWindows 7 systems with no problem. The XP and Windows 7 use different versions of Internet Explorer.

    I would suggest you defragment your drive and registry before going further. You have probably have a lot of "garbage" in both areas. This will cause odd system behaviour.

  10. #10
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Hallo Leith Ross,

    I also tried to use the code from the following video, which also uses google:
    https://www.youtube.com/watch?v=GswfT0Mrr5M

    But when I ran the exact same code (IE.Document.all("q").Value = "TestString"), it still did not put "TestString" into the google search box.

    Since only excel and IE are involved in this task, why would defragmenting my drive and registry help?

  11. #11
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    I tested and Leith's code works fine - but why would you go all this trouble to open google and put in 'searchstring'

    Why not make the search string part of the url?

    "https://www.google.com/?gws_rd=ssl#safe=off&q=searchstring"
    Please click the * below if this helps

  12. #12
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Ultimately, I want to log in to another page and download data from there to excel ... google was just an example that I used to test the code ... is it possible that my company's IT department's security settings prevent me from using the code necessary for web scraping?

  13. #13
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    Anything is possible.

    Can you share the other page and data you want to get to excel?

  14. #14
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    https://www.moodys.com/

    ... I want to automatically fill in my username and password ... but I am not able to "catch" this stupid textbox ...

  15. #15
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    Please Login or Register  to view this content.
    Last edited by JasperD; 04-09-2015 at 04:42 PM.

  16. #16
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    Thank you for the code JasperD,


    .... unfortunately it didn't work either. .... my computer must be cursed or sth. ... these web scraping things simply do not work on this computer.

  17. #17
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    Well, it should log you in, providing you put your username and password in the code.

    What responsetext do you get (debug.print moodys.responsetext)? I obviously get a "not logged in one", but do you get the same as below?

    {"passwordSharing":0,"isLoggedIn":false,"isLinked":false,"userId":null,"redirectUrl":null,"notify":null,"error":"A Username and Password are required for access to Moodys.com.","style":"WarningMessage"}

  18. #18
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    I put my username and password in the code. ... I do not get any response ...

  19. #19
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    You don't get any response where...?
    The macro won't give any output, it just logs you into the site.

    Change it as below and run it - tell me if what you get in the message box is the same as what I posted before.

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    11-25-2014
    Location
    Frankfurt, Germany
    MS-Off Ver
    2007
    Posts
    13

    Re: IE.Document.getElementById("ID") not working!

    I found the reason why it didn't work ... my company's IT Department has disabled the web scraping functions ... Thank you all for your help ... because your code failed as well, I got the idea that it was all about the configurations set by the IT department ... this idea was confirmed today by IT.

  21. #21
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: IE.Document.getElementById("ID") not working!

    Thanks for the update.
    However, if you can reach it via IE, then it should be doable via VBA... just saying ;-)

  22. #22
    Registered User
    Join Date
    12-13-2017
    Location
    INdia
    MS-Off Ver
    2016
    Posts
    1

    Re: IE.Document.getElementById("ID") not working!

    Alert me | Edit | Delete | Change type
    Question
    You cannot vote on your own post
    0
    PLease help!!!

    Sub IE_Autiomation()
    Dim ie As InternetExplorerMedium
    Dim OrgBox As HTMLInputElement

    url = ""

    Set ie = New InternetExplorerMedium
    ie.Visible = True
    ie.Navigate url
    Do
    If ie.ReadyState = 4 Then
    Exit Do
    Else
    DoEvents
    End If
    Loop

    Set doc = ie.Document

    ie.Document.getElementById("cxn-additem-btn").Click '' works fine
    ie.Document.getElementById("cxn-add-btn").Click ''works fine
    Set OrgBox = ie.Document.getElementById("pin-url") ''Issue is here
    OrgBox.Value = "Hello"
    I am getting error 424 object required.. I am running code using F8(manually). Page loading is taken care.

    Please let me know if you find any solution for this

+ 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. document.execCommand "Copy" has stopped working with Internet Explorer
    By Dan_Q in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2016, 06:22 AM
  2. input type "hidden" onclick "document.text.submit ...for web login and parsing
    By hgtenn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2014, 08:40 PM
  3. [SOLVED] IF Formula not working - need to return "NO" if cell is 1% greater or "YES" if less 1%
    By maryren in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-26-2013, 11:34 AM
  4. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM
  5. Replies: 0
    Last Post: 08-07-2006, 01:35 AM

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