Reputation: 57
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> ' + title;
} else {
internalMenu.style.display = "none";
obj.innerHTML =
'<IMG SRC="/images/menu-arrow.gif" ' +
'border=0> ' + 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
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:
VBA:
You apply CSS selector using .querySelector
method of document
ie.document.querySelector("input[src='/img/go_button.gif']").Click
Upvotes: 1
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