简体   繁体   中英

vb.net programming a button press on a website

I am working with Visual Studio Express 2013 and trying to program some code to press a button on the web page. I have read many examples and gotten similar examples but none seem to be working on mine. Below is the code

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim IE As SHDocVw.InternetExplorer


IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

IE.Navigate("http://www.timeanddate.com/date/weekdayadd.html")

Do Until IE.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE

Loop


Dim elementcol As Object
elementcol = IE.Document.getelementsbyclassname("bigger")

elementcol.invokemember("click")




End Sub

This is from many examples but none of it seems to work. Could anyone provide me with some feedback. I am referencing shdocvw.dll, HTML Dialogs 1.0 Type Library, Microsoft HTML Object Library, and Microsoft Internet Controls.

It makes it to the final line and breaks.

Could I get ideas from anyone why this isn't working?

Thanks so much for your feedback!!

Which button are you trying to click? the bigger class only refers to the set to today link. for this you would be better off getting a collection of HTML A elements, checking its innerHTML for "Today" then invoking the click

like so

        Dim IE As SHDocVw.InternetExplorer
        IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.Navigate("http://www.timeanddate.com/date/weekdayadd.html")

        Do Until IE.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
            Application.DoEvents()
        Loop
        Dim elementcol As Object
        elementcol = IE.Document.getelementsbytagname("A")
        For Each f In elementcol
            If f.InnerHtml = "Today" Then
                f.click()
                Exit For
            End If
        Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM