Jump to content

onChange event on a webpage combox


meow

Recommended Posts

Hey guys,

 

So I'm in a hockey pool at work and we have our own little program reading the NHL stats on their website. It's been working for years.

 

Here's the link to the NHL stats: http://www.nhl.com/stats/player?aggregate=1&gameType=2&report=skatersummary&pos=S&reportType=season&seasonFrom=20162017&seasonTo=20162017&filter=gamesPlayed,gte,1&sort=points,goals,assists

 

The problem now is that NHL changed the way to navigate to the next page. Last year it was a "next" link button. So we'd find that button and call the "click" event on it.

 

But as you can see in the link, at the bottom...it is now a combobox...and I can't seem to fire the onChange event. I can change the value just fine...but it won't go to the next page of stats.

 

 

Here's a quick and easy example of code in vb.net (please do not waste time judging the code or whatever, I'm just trying to find a way to fire the onChange event).

I have tried many ways that I found on google, but nothing seems to work. Anyone nice enough to try it out or tell me how to do it? Thanks.

 

I dont know whats wrong with the colors in the spoiler tag lol. just copy paste in vb.net

 

 

Imports SHDocVw
Imports MSHTML

Module Module1

    Sub Main()
        Dim ie As InternetExplorer

        ie = New InternetExplorer
        ie.Visible = True

        ie.Navigate("http://www.nhl.com/stats/player?aggregate=1&gameType=2&report=skatersummary&pos=S&reportType=season&seasonFrom=20162017&seasonTo=20162017&filter=gamesPlayed,gte,1&sort=points,goals,assists")

        Do
        Loop Until ie.ReadyState = tagREADYSTATE.READYSTATE_COMPLETE

        Dim all As IHTMLElementCollection
        all = ie.Document.all

        For Each elem As IHTMLElement3 In all
            If elem.className = "page-select-container" Then
                Dim pagerSelect As IHTMLSelectElement
                pagerSelect = elem.all(0) 'get the combobox

                pagerSelect.selectedIndex = 2 ' <--- This changes the value in the combox


                ''''the onchange event never works...
                pagerSelect.FireEvent("onChange", pagerSelect)
                pagerSelect.FireEvent("onChange")
                ''''
            End If
        Next

        ie.Quit()
    End Sub

End Module

 

 

Link to comment
Share on other sites

You could use something like selenium with Java.


I realize that's probably not necessarily what you're looking for but it could be easier and more efficient down the road.

Link to comment
Share on other sites

You could use something like selenium with Java.

I realize that's probably not necessarily what you're looking for but it could be easier and more efficient down the road.

 

That's actually interesting.

 

But our hockey pool program is not my own and it works in VBA Excel and no one wants to redo it all.

 

Thanks for sharing though

Link to comment
Share on other sites

That's actually interesting.

 

But our hockey pool program is not my own and it works in VBA Excel and no one wants to redo it all.

 

Thanks for sharing though

I don't much know about VBA unfortunately, otherwise I'd be more than willing to help. I just know that we use Selenium for RTA at work, though come to think of it, that may not be the best approach for this.

 

That being said, have you considered getting the data differently? Rather than working with the page's elements, couldn't you work with some sort of API or query to get the results in a less bloated way?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.