2

I have a problem to click on button on an internet website, I cannot display the full VBA code because it is about a sensitive website used on a professional environment.

What I would like that my excel macro does is to display the website desired (this part, my macro does it perfectly) , then I would like that my macro click on one specific button on this website, after inspecting the HTML code of this button, it returns me the following HTML code:

<div title="Export Datas" class="pExportdatas pButton"><span></span></div>

I have tried different instructions in VBA (please find them below) to click on this button but every time unsuccessfully (the macro does not perform this Action, the macro does not return me any error message but the button is unfortunately every time not clicked).

HTMLDoc.all("pExportdatas pButton").Click   
objIE.document.getElementById("pExportdatas pButton").Click
objIE.document.querySelector("button[class*= pExportdatas pButton]").Click

In case, someone knows the solution, it would be really super. Many Thanks in advance Xavi

1 Answer 1

1

You can't have compound class names in a css selector. Try the following attribute = value selector

objIE.document.querySelector("[title='Export Datas']").click

Or

objIE.document.querySelector("div.pExportdatas.pButton").Click

If you get a not found error then make sure you have a proper wait before

While objIE.Busy Or objIE.readyState < 4: DoEvents: Wend

and also check there is no parent frame/iframe to negotiate.

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

5 Comments

thanks a lot QHarr for your reply and this tips, I tried your code but unfortunately, the button is not clicked yet...
what is happening? Any error messages? You can also try objIE.document.querySelector("[title='Export Datas']").FireEvent("onclick")
no error messages at all, it is just that the button is not clicked... I tried also objIE.document.querySelector("[title='Export Datas']").FireEvent("onclick") but same result, no error message but the button is not clicked.... there is probably something inside the html code related to this button which is more complex... When the button is clicked on this website, it should normally download an excel file...
Upvotes welcome but you shouldn’t accept as answer as it may put other people off trying to answer. I will have another look later. In the meantime we may need to see more html.
Thanks Qharr, I undid the acceptance of youranswer

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.