Search code examples
excelvbawebautomation

Excel VBA to click item in html div class


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>

Solution

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

    HTMLDoc.querySelector("a[title='Sign In']").click