none
HTMLSelectElement doesn't update after I change its value RRS feed

  • Question

  • Hello,

    If you access http://www.scoutscartola.com/mercado and change the value of the combo 'Time', you'll see the table below refresh with players that belong to that team. The problem is that if I changed it programatically, it won't refresh. So far, I tried:

    'Add library references to:
    '-Microsoft Internet Explorer Controls
    '-Microsoft HTML Object Library
    
    Sub NavigationTest()
        Dim ie As SHDocVw.InternetExplorer
        Dim iOptionElement As MSHTML.HTMLOptionElement
        Dim SelectElement As MSHTML.HTMLSelectElement
        
        Set ie = New InternetExplorer
        ie.Visible = True
        
        ie.navigate "http://www.scoutscartola.com/mercado"
        Do While ie.Busy: DoEvents: Loop
        
        Set SelectElement = ie.Document.all.Item("data[filtro_time]")
        SelectElement.Focus
        SelectElement.selectedIndex = 1
        SelectElement.FireEvent "onChange"
        
    '    ie.Quit
    End Sub
    

    The html code for the SelectElement is 

    <select name="data[filtro_time]" id="filtro_time">

    So it doesn't have a onChange event that I can fire.

    I'd like to update the table as I change the selected team programatically.

    Thanks!



    http://www.ambienteoffice.com.br || Grupo de WhatsApp: https://chat.whatsapp.com/K1uey5Q4yJdKnsgWkVQAZG

    Monday, January 2, 2017 12:55 PM

All replies

  • I looked at this with Selenium and for some reason it can't find the select element.  Firefox's Firepath has no problem finding it.  I clearly see it in the html and there is no iframe or other elements in there to hide.  I tried it in Chrome, IE, Firefox and Edge with the same results.  At a loss to explain it.
    Monday, January 2, 2017 3:41 PM
  • Thanks, Mogulman.

    If I could find the event where JS updates the table, my problem would be solved by firing it, but no luck so far.


    http://www.ambienteoffice.com.br || Grupo de WhatsApp: https://chat.whatsapp.com/K1uey5Q4yJdKnsgWkVQAZG

    Monday, January 2, 2017 8:39 PM
  • The select is an HTML element and independent of Javascript.  What I don't understand is why Selenium can't find the element.  I use xpath so this should work "//select[@id='filtro_time']".  If I get a chance I'll play with it tomorrow.  I've given up on Microsoft Internet Controls.  It seems to fail more than it works.
    Tuesday, January 3, 2017 2:08 AM
  • Ok, I got it to work.  Selenium uses a special Select element for selecting 'select' elements.  It changes the Time select perfectly and it updates the table.  I used Edge in the example.  

    About Selenium:

    I would use Selenium Basic rather than Microsoft Internet Controls to extract webpage content.  It comes with a lot of Excel examples.  It supports selecting elements with Xpath which is extremely powerful.  It supports Firefox, Chrome, IE and Edge.  I've done 3 projects with it and was impressed.  My latest project searches Overdrive public libraries for new books I want to read.  It was well supported but hasn't been updated since March.  I downgraded to Firefox 46.0.1 which works.  There are posting on how to update the Chrome and Edge drivers.  The IE driver seems to work.  Selenium in general can be used with C#, Java, Ruby and other languages.  Someone developed Selenium Basic which supports VB.NET and VBA.

    Dim drv As Selenium.WebDriver
    Dim ele As Selenium.WebElement
    Dim eleSel As SelectElement
    
    Sub SelectSet()
       '' Add reference to selenium type library
      Set drv = New Selenium.EdgeDriver
      Dim xPath As String
      Dim browser As String
    
      drv.Get "http://www.scoutscartola.com/mercado"
      drv.Wait (3000)
      drv.Window.SetSize 1200, 1000
      drv.Window.SetPosition 0, 0
      browser = drv.Manage.Capabilities.Get("browserName", 0)
      xPath = "//select[@id='filtro_time']"
      If GetElementSelect(xPath) Then
        eleSel.SelectByText "Botafogo"
      End If
    End Sub
    
    Function GetElementSelect(xPath As String) As Boolean
      Dim e As String
      On Error GoTo Handler
      
      Set eleSel = drv.FindElementByXPath(xPath).AsSelect
      GetElementSelect = True
      Exit Function
    Handler:
      e = Err.Description
      GetElementSelect = False
    End Function
    
    Function GetElement(xPath As String) As Boolean
      On Error GoTo Handler
      
      text = ""
      Set ele = drv.FindElementByXPath(xPath)
      text = ele.text
      GetElement = True
      Exit Function
    Handler:
      Err.Clear
      GetElement = False
    End Function
    
    Function GetElementClick(xPath As String) As Boolean
      On Error GoTo Handler
      
      text = ""
      Set ele = drv.FindElementByXPath(xPath)
      ele.Click
      drv.Wait (1000)
      GetElementClick = True
      Exit Function
    Handler:
      Err.Clear
      GetElementClick = False
    End Function
    


    • Edited by mogulman52 Wednesday, January 4, 2017 1:31 PM
    Wednesday, January 4, 2017 1:30 PM