Search code examples
vbaweb-scrapinggetelementbyid

Run-time error '424' getElementById


I am trying to automate a process where I need to enter some data in a website textbox. I reused a code that works well for a different site, but here I get a "runtime error 424: object required" when I attempt to enter a value using GetElementByID

This is the link to the site:
http://www.e-post.co.il/?page_id=723

(I am interested in updating the upper text box)

and the code:

Sub main()
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "http://www.e-post.co.il/?page_id=723"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.Document.getElementById("num_with_letters").Value = "IP1210665"   
End Sub

Solution

  • I can't believe I didn't spot this at the time. Your element is within an iframe. You can use the iframe src url direct

    Public Sub EnterInfo()
        Dim ie As InternetExplorer
        Set ie = New InternetExplorer
        With ie
            .Visible = True
            .navigate "http://run.hfd.co.il/run_public3/"
    
            While .Busy Or .readyState < 4: DoEvents: Wend
    
            .document.getElementById("num_with_letters").Value = "IP1210665"
    
            Stop      
       End With
    End Sub
    

    If you want to use the original url you need to navigate the iframe as follows:

    .document.getElementsByTagName("iframe")(0).contentDocument.getElementById("btn_eur")