0
        <div id="CSV"
            <li style="width: 100%; float: left; clear: left;"> 
            <input onclick="go('CSV')" type="button"
                value="Download in CSV Format" />
            </li>
        </div>

Trying to download the file by using the onclick function. I have tried the following code, it executes but doesn't download the file.

Set x = ie.document.getElementById("CSV")
x.Click

Also x.onclick gives error and x.FireEvent "onclick" also doesn't work. Please help.

6
  • The I'd excel isn't there, CSV is, but you need tagname of a Commented Feb 1, 2016 at 21:58
  • @Nathan_Sav Sorry I have edited that but problem is still the same. There is no tag name and I don't know why but the website still works when I click it manually? Commented Feb 1, 2016 at 22:05
  • 'CSV' is the ID of the parent element (the div) that houses the input element. You need to target the <input> tag - not the <div> tag Commented Feb 1, 2016 at 22:07
  • @MacroMan I was trying that only for quite sometime but the GetElementsByvalue does not work and I think it isn't a valid function. There is no other identifier left and that's the reason I am stuck. Most of the time I match the innertext and use navigate function but not here. Commented Feb 1, 2016 at 22:23
  • @Jain GetElementsByTagName("input") ;) - That will return a Collection object though of all <input> elements so you will have to loop through and test the properties of each one to get the one you want. Then you can use the .Click method. Commented Feb 1, 2016 at 22:24

2 Answers 2

1
Set div = ie.document.getElementsByTagName("input")
'loop through all the elements
For Each x In div
    ' check if the value matches the required value, if it does then use the .click function. 
    If Trim(x.Value) = "Download in CSV Format" Then
        x.Click
        Exit For
    End If
Next
Sign up to request clarification or add additional context in comments.

1 Comment

Your contribution would have more value if you add some explanation why the suggested approach solves the problem. The logic may not be apparent to everyone...
0

You can also use CSS selector of

input[onclick=go('CSV')]

This says get the input tag with property onclick= go('CSV').

CSS selector

This can be deployed as

ie.document.querySelector("input[onclick=go('CSV')]").Click

The .querySelector method applies the CSS selector to the HTMLdocument.

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.