1

I have been trying to click the input button on a web page using JavaScript. I have tried the following:

HTML

<input type="image" src="/img/go_button.gif">

VBA

 ' Not working 
el.click

 ' Not working

el.focus 
el.invokemember("OnClick")

JavaScript

function toggleMenu(obj, title)
{
    var internalMenu = obj.parentNode.getElementsByTagName("div").item(0);
    var d = internalMenu.style.display;
    if (d != "block") {
        internalMenu.style.display = "block";
        obj.innerHTML =
            '<IMG SRC="/images/menu-arrow-open.gif"'
            + ' border=0>&nbsp;' + title;
    } else {
        internalMenu.style.display = "none";
        obj.innerHTML =
            '<IMG SRC="/images/menu-arrow.gif" ' +
            'border=0>&nbsp;' + title;
    }
}

I have been searching Google, but I haven't found any solution yet.I've seen a method called ie.Document.parentWindow.execScript, but I'm not sure how to use it.

Is it possible to click that image button and take whatever results I want?

3
  • Does the button work without the image on it? Commented Nov 28, 2014 at 5:54
  • Which is the part of Excel in this case? If the VBA is running in Excel, how do you get the el? Are you sure you have the right element? Is the <input type="image"> a FORM's submit button? If so, why not simply submit the FORM? Commented Nov 28, 2014 at 6:52
  • Im sure about that .. i able to loop though each input element in the web page . i did inspect element for that button. and i pasted the html content in my question Commented Nov 28, 2014 at 10:23

3 Answers 3

1

CSS selector

No need for a loop. Use a CSS selector of:

input[src='/img/go_button.gif']

This specifies input tag with attribute src having value '/img/go_button.gif'


CSS query:

CSS query


VBA:

You apply CSS selector using .querySelector method of document

ie.document.querySelector("input[src='/img/go_button.gif']").Click
Sign up to request clarification or add additional context in comments.

Comments

0

This is what I would do:

A. Get all the input elements in the page:

Set allInputs = ie.document.getElementsByTagName("input")

B. Looping through them and clicking the one which refers to the image "go":

For Each element In allInputs
    If element.getAttribute("src") = "/img/go_button.gif" Then
        element.Click
        Exit For
    End If
Next element

1 Comment

Thanks for the code. But it doesnt't worked. i already tried this method .But no luck ..code simply passes that line (el.click) :(
0

$('input[type="image"]').trigger('click');

should do it

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.