• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

document.getElementById("btnsearch").Click is not working

SniperHex

New Member
Hi there. I got a code from this forum that was done by Marc L but the problem is Click button is not working. I tried to focus on the button before clicking, also with no success. The code is below if someone could help:
---------------------------------------------------------------------------

Code:
Sub Demo()
    With CreateObject("InternetExplorer.Application")
        .navigate ("http://quhtani.com/sms/0quh01/q")
        .Visible = True
        While .readyState < 4 Or .Busy:  DoEvents:  Wend
        .document.getElementsByName("srch-term").Item.innerText = "966550512345"
        .document.getElementById("btnsearch").Focus
        .document.getElementById("btnsearch").Click
    End With
    End
End Sub
--------------------------------------------------------------------------------------------
Mod edit: Added code tag.


▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !
 
Last edited by a moderator:
Please use code tag. I've edited it this time.
upload_2018-5-9_14-11-16.png

Your issue isn't simulating click. But setting the "srch-term".

You can't write to .Item.InnerText

But you should write .Item.Value

So...
Code:
Sub Demo()
With CreateObject("InternetExplorer.Application")
    .navigate ("http://quhtani.com/sms/0quh01/q")
    .Visible = True
    While .readyState < 4 Or .Busy: DoEvents: Wend
    .document.getElementsByName("srch-term").Item.Value = "966550512345"
    .document.getElementbyId("btnsearch").Click
End With
End Sub
 
SniperHex, I was searching your thread in the VBA forum,
the reason why I didn't find it !
Thanks for your next VBA thread to create it in the appropriate VBA forum …

Without the link of the source code original post,
I just can advise a working code for a webpage may not work
for another one. So for any webpage you must observe how it works …
 
Thank you so much for your help. It works like a charm.
one more question plz.
How i can count the result items I get after clicking search button?
Can I count it by class name or any other way? Thank you for your patience :)
 
Apart from the method sir chihiro has already shown, you can try like this as well to serve the same purpose:
Code:
Sub Demo()
    With CreateObject("InternetExplorer.Application")
        .navigate ("http://quhtani.com/sms/0quh01/q")
        .Visible = True
        While .ReadyState < 4 Or .Busy:  DoEvents:  Wend
        .Document.getElementById("srch-term").Focus
        Application.SendKeys "966550512345"
        .Document.getElementById("btnsearch_loop").Click
    End With
End Sub
 
There's a load-more button at the bottom of the page that loads more results. Any idea how to click that button automatically ?!!

Thank you
 
Back
Top