2

I need to click on the button but something goes wrong. Error raise "Object doesn't support this property or method" I have used this code

Sub test()
Dim ie As Object
Set ie = New InternetExplorer

ie.navigate "http://www.spark-interfax.ru/system/home/card#/company/3411D127F25A45F7ABAB32964A32848D/427"

ie.Visible = True

While ie.Busy Or ie.readyState < 4: DoEvents: Wend
ie.document.getElementsByClassName("button-icon right-offset-5 sp-i-xls-download-grey").Click
End Sub

On web-page this button is shown as this code

<button type="button" class="btn btn-default btn-sm js-not-print"><i class="button-icon right-offset-5 sp-i-xls-download-grey"></i><span>Excel</span></button>
5
  • Button has class="btn btn-default btn-sm js-not-print" - I may not work or you may use properties like firstElementChild, nextElementSibling, previousElementSibling, etc. to get to proper element, also tagName can help identify if it is right one. Commented Sep 9, 2019 at 12:34
  • You probably want to use querySelectorAll if you are wanting to get by multiple classes (if that is js?) Commented Sep 9, 2019 at 12:38
  • Is this post login? And what do you mean by something goes wrong ? Commented Sep 9, 2019 at 13:33
  • It's button for downloading file Commented Sep 9, 2019 at 13:48
  • Error raised "Object doesn't support this property or method" Commented Sep 9, 2019 at 13:50

1 Answer 1

1

Your error is because you are attempting to invoke a method of a single node on a collection.

This

ie.document.getElementsByClassName("btn btn-default btn-sm js-not-print")

returns a collection. Note: I changed the class name but principle remains.

You would need to index into the collection to get the right node e.g.

ie.document.getElementsByClassName("btn btn-default btn-sm js-not-print")(0).Click

If it is the first node you need to match you could try querySelector

ie.document.querySelector(".btn.btn-default.btn-sm.js-not-print").click

and ideally see if you can remove some of the compound class values (the class attribute is multi-valued i.e. more than one value -seperated by spaces in source) e.g.

ie.document.querySelector(".btn.js-not-print").click
Sign up to request clarification or add additional context in comments.

Comments

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.