I'm currently using internet explorer to navigate to a web page and then
click on a button. There are two buttons on this page. The following is the
HTML code.

<input type=submit name=button value=edit>
<input type=submit name=button value=delete>

I want to click on the delete button. Currently, I use th following code to
do so.

oIE.Document.Forms(0).Item("button")(0).Click

Which works fine but I was wondering is there a more "correct" way to do
this by refering to the button you want to click on by value? I want my code
to work even if they switch the order of the buttons. I was thinking
something along the lines of

oIE.Document.Forms(0).Item("button")("Delete").Click

Am I on the right track here?

-J

Re: Scripting Internet Explorer... by Evertjan

Evertjan
Sat Jan 17 17:02:25 CST 2004

J S wrote on 17 jan 2004 in microsoft.public.scripting.vbscript:

> I'm currently using internet explorer to navigate to a web page and
> then click on a button. There are two buttons on this page. The
> following is the HTML code.
>
> <input type=submit name=button value=edit>
> <input type=submit name=button value=delete>
>
> I want to click on the delete button. Currently, I use th following
> code to do so.
>
> oIE.Document.Forms(0).Item("button")(0).Click
>
> Which works fine but I was wondering is there a more "correct" way to
> do this by refering to the button you want to click on by value? I
> want my code to work even if they switch the order of the buttons. I
> was thinking something along the lines of
>
> oIE.Document.Forms(0).Item("button")("Delete").Click

It seems to me much easier to submit the form and leave the button alone:

<input type=hidden name=button id=b1 value="">
<input type=button value=edit onclick="subm("edit")">
<input type=button value=delete onclick="subm("delete")">

...

function subm(x) '' x is "edit" or "delete"
document.getElementById("b1").value=x
oIE.Document.Forms(0).submit()
end function


not testd, its the idea only


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Scripting Internet Explorer... by J

J
Sat Jan 17 18:03:54 CST 2004

One thing I forgot to mention is that I have no control over the content of
the web page to which I am trying to automate access (Its a third party
webpage).

"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns9474696888Eeejj99@194.109.133.29...
> J S wrote on 17 jan 2004 in microsoft.public.scripting.vbscript:
>
> > I'm currently using internet explorer to navigate to a web page and
> > then click on a button. There are two buttons on this page. The
> > following is the HTML code.
> >
> > <input type=submit name=button value=edit>
> > <input type=submit name=button value=delete>
> >
> > I want to click on the delete button. Currently, I use th following
> > code to do so.
> >
> > oIE.Document.Forms(0).Item("button")(0).Click
> >
> > Which works fine but I was wondering is there a more "correct" way to
> > do this by refering to the button you want to click on by value? I
> > want my code to work even if they switch the order of the buttons. I
> > was thinking something along the lines of
> >
> > oIE.Document.Forms(0).Item("button")("Delete").Click
>
> It seems to me much easier to submit the form and leave the button alone:
>
> <input type=hidden name=button id=b1 value="">
> <input type=button value=edit onclick="subm("edit")">
> <input type=button value=delete onclick="subm("delete")">
>
> ...
>
> function subm(x) '' x is "edit" or "delete"
> document.getElementById("b1").value=x
> oIE.Document.Forms(0).submit()
> end function
>
>
> not testd, its the idea only
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)



Re: Scripting Internet Explorer... by Alexander

Alexander
Sun Jan 18 21:56:22 CST 2004

am 17.01.2004 23:24 sprach J S dieses:

> I'm currently using internet explorer to navigate to a web page and then
> click on a button. There are two buttons on this page. The following is the
> HTML code.
>
> <input type=submit name=button value=edit>
> <input type=submit name=button value=delete>
>
> I want to click on the delete button. Currently, I use th following code to
> do so.
>
> oIE.Document.Forms(0).Item("button")(0).Click
>
> Which works fine but I was wondering is there a more "correct" way to do
> this by refering to the button you want to click on by value? I want my code
> to work even if they switch the order of the buttons. I was thinking
> something along the lines of
>
> oIE.Document.Forms(0).Item("button")("Delete").Click
>
> Am I on the right track here?

It's somehow the right direction of thinking, but HTML-Elements usually
only get referenced by Name or by ID afaik,
not by their Value-property. So item ("Delete") wont work or only return
elements with name/id "Delete".
If you only can rely on the buttons label (e.g value) then just scan
the DOM for elements with such a label, that are also input-elements
(type "submit") and named "button":


Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "about:<input type=submit name=button value=edit>" _
& vbcr & "<input type=submit name=button value=delete>"

ie.Visible = true
Set document = ie.Document
Set elemsNamedButton = document.getElementsByName ("button")

For each el in elemsNamedButton
if "input" = LCase (el.TagName) AND "delete" = el.value then
Set myVeryButton = el
Exit For
end if
Next

If "HTMLInputElement" = TypeName (myVeryButton) Then
Set myVeryButton.onclick = GetRef ("clickClick")
myVeryButton.click()
Else
MsgBox "couldnt find button"
End If

Sub clickClick ()
MsgBox "got clicked by Script, GoodBye"
ie.Quit : WScript.Quit()
End Sub

--
Gruesse, Alex