0

I'm a newbie working in my first web automation with Excel VBA. I was able to make progress so far but got stuck with trying to click on what looks like a button on the website. Please let me know if you can help me, I appreciate it. Thank you! The particular element is within the a tag in the below html code:

<div class="sh-c-btn-group">
    <input name="pf.ok" type="hidden" value="">
    <input name="pf.cancel" type="hidden" value="">
    <a title="Sign In" class="sh-c-btn sh-c-btn--primary" onclick="postOk();">Sign In</a>
</div>
3
  • Have you tried getElementsByName("pf.ok")(1).Click? Commented Jul 7, 2019 at 14:48
  • I did try the getElementsByName("pf.ok")(0).Click but nothing happens -- index # (1) threw an error -- also tried getElementsByClassName("sh-c-btn sh-c-btn--primary").Click unsuccessfully Commented Jul 7, 2019 at 15:58
  • It just be tied to the onclick event. Try using div.FireEvent "onclick". This is a good reference. stackoverflow.com/questions/31221853/… Commented Jul 7, 2019 at 16:43

3 Answers 3

1

You can avoid looping by using the querySelector method...

HTMLDoc.querySelector("a[title='Sign In']").click
Sign up to request clarification or add additional context in comments.

Comments

1

Jenn & Jumpgroup, thanks so much for the help :) managed to do it with the following loop by getting the title and classname:

Dim HTMLas As MSHTML.IHTMLElementCollection
Dim HTMLa As MSHTML.IHTMLElement

Set HTMLas = HTMLDoc.getElementsByTagName("a")

For Each HTMLa In HTMLas
    If HTMLa.getAttribute("title") = "Sign In" And HTMLa.getAttribute("classname") = "sh-c-btn sh-c-btn--primary" Then
        HTMLa.Click
    Exit For
    End If
Next HTMLa

Comments

0

This code loops until the page is loaded: Do DoEvents Loop Until objIE.readystate = 4

1 Comment

I've put in the loop until the page is fully loaded and am able to fill out several forms after the page is fully loaded. But somehow can't get that one item to click.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.