user3114645
user3114645

Reputation: 57

Trying to click submit button which as image as button vba

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?

Upvotes: 1

Views: 3221

Answers (3)

QHarr
QHarr

Reputation: 84455

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

Upvotes: 1

b_dubb
b_dubb

Reputation: 421

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

should do it

Upvotes: 0

Matteo NNZ
Matteo NNZ

Reputation: 12645

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

Upvotes: 0

Related Questions