1

I am attempting to click this login button on a website using VBA, here is the HTML for the button:

<input type="submit" value="Login" onclick="submitForm();">

I have already got it to the point where it enters my username and password as those fields had names but I am unable to get it to click this button as it does not have a name. I have been searching and either I do not know what I am looking for or this must not be that common of an issue. Here is my latest attempt:

objIE.document.getElementsByName("Login")(0).Click

Thanks!

2
  • objIE.document.getElementsByName("Login")[0].click(); Commented Nov 27, 2018 at 20:15
  • @DarthMoon Syntax error my friend, this is run within Excel using VBA. Commented Nov 27, 2018 at 20:25

1 Answer 1

3

As you state: there is no name attribute in the HTML for the element you show. You can use an attribute = value CSS selector to target the attributes that are present:

objIE.document.querySelector("[onclick='submitForm();']").click

Same idea means

objIE.document.querySelector("[value=Login]").click

Or even

objIE.document.querySelector("[type=submit]").click

Finally, you may be able to submit the form direct with

objIE.document.getElementsByTagName("form")(0).submit

If there is more than one element that can be matched on the attribute selector then use .querySelectorAll to retrieve them all and index into the returned nodeList to get the right one e.g.

objIE.document.querySelectorAll("[type=submit]").item(1).click

Where 1 in the above would be the second matched. 2 would be the third etc.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfectly and your answer provided multiple different ways to accomplish the task. I appreciate you giving multiple variances, I am sure this answer will help many in the future. Thanks!

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.