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