Consulting

Results 1 to 9 of 9

Thread: Not able to access elements on a web page

  1. #1

    Not able to access elements on a web page

    Hi,

    I am trying to use VBA to access the login form on this page
    http://forum.wordreference.com/newthread.php?do=newthread&f=6

    For some reason I am not able to fill the username and password textboxes. The watch window of VBA shows me the values of the elements are changing but I am not able to see any text on the webpage.

    Please see my code below.
    Set ObjIE = CreateObject("InternetExplorer.Application")
     
      With ObjIE
     
      .Visible = 1
      .navigate "http://forum.wordreference.com/newthread.php?do=newthread&f=6"
     
     
       Do While .Busy: DoEvents: Loop
       Do While .readyState <> 4: DoEvents: Loop
     
     
      Set htmlDoc = .document
      htmlDoc.getElementById("vb_login_username").Value = "ABC"
      htmlDoc.getElementById("vb_login_password").Value = "DEF"
     htmlDoc.forms(2).submit
    End with
    

    Thanks.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    [VBA]Sub t()
    Dim ObjIE As Object, htmlDoc As Object
    Set ObjIE = CreateObject("InternetExplorer.Application")

    With ObjIE

    .Visible = 1
    .navigate "http://forum.wordreference.com/newthread.php?do=newthread&f=6"


    Do While .Busy: DoEvents: Loop
    Do While .readyState <> 4: DoEvents: Loop


    Set htmlDoc = .document
    htmlDoc.getElementByID("navbar_username").Value = "ABC"
    htmlDoc.getElementByID("navbar_password").Value = "DEF"
    htmlDoc.forms(1).submit
    End With

    End Sub[/VBA]

  3. #3
    Thanks Kenneth.

    I knew about the login box at the top right, that you are using to login into the website.

    However, I was more interested in finding out why I am not able to access the main login form. Why can't I access those textboxes?

    Thanks.

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Use forms(1). I am not sure why the forum is changing the indentation.
    [vba]Sub LoginWordReference1()
    Dim ObjIE As Object, htmlDoc As Object
    Set ObjIE = CreateObject("InternetExplorer.Application")
    With ObjIE
    .Visible = 1
    .navigate "http://forum.wordreference.com/newthread.php?do=newthread&f=6"
    Do While .Busy: DoEvents: Loop
    Do While .readyState <> 4: DoEvents: Loop
    Set htmlDoc = .document
    htmlDoc.getElementByID("vb_login_username").Value = "ABC"
    htmlDoc.getElementByID("vb_login_password").Value = "DEF"
    htmlDoc.forms(1).submit
    End With
    End Sub[/vba]

  5. #5
    Thanks Kenneth.

    No, this is not working.

    If you single step through your code, you will notice that the getelementbyID statements are not able to put those values into the username and password boxes.

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    I seldom post code that does not work for me.

  7. #7
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Kenneths code fills in both textboxes just fine on my machine. (in excel 2003 and 2007)

  8. #8
    Thanks folks.

    This is strange. I tried Kenneth's code both on my work machine and home machine to no avail. Both machines have Windows XP and Office 2003.

    I am attaching a screenshot from my home machine. You can see in the screeshot that the text boxes on the webpage are empty even after the code execution is past the getelementbyID statements. Similar code works fine for other websites on both machines. I don't know what is going on.

    Thanks.
    Attached Files Attached Files

  9. #9
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    I am not sure if I have 2003 anymore. I use 2010. The more important version is MSIE. I use version 9.0.8112.16421. I will see if my old computer has the old versions tomorrow.

Posting Permissions

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