Consulting

Results 1 to 10 of 10

Thread: IE automation: able to change dropdown list value but webpage doesn't update

  1. #1

    IE automation: able to change dropdown list value but webpage doesn't update

    The webpage: https://www.avanzabank.se/aktier/lista

    I want it to update when I change the value of the second dropdown list "Lista".

    The list:
    HTML Code:
    <select id="list" class="list" name="listKey">
    <option value="large_cap_se"></option>
    <option value="mid_cap_se"></option>
    <option value="small_cap_se"></option>
    <option value="firstnorth_se"></option>
    <option value="aktietorget"></option>
    <option value="ngm_equity"></option>
    <option value="ngm_mtf"></option>
    <option value="inofficiella"></option>
    <option value="xterna_listan"></option>
    </select>
    VBA-code:
    [VBA]IE(0).Document.getElementById("list").SelectedIndex = 2
    IE(0).Document.getElementById("list").FireEvent ("onchange")[/VBA]
    I have also tried:
    [VBA]IE(0).Document.getElementById("list").onchange[/VBA]
    without success.
    Last edited by Sandstedt; 11-15-2012 at 11:41 AM.

  2. #2
    From what I understand, the dropdown list should trigger a javascript function but is unable to do so when I change its value in VBA.

    I have tried to find the name of the function and its parameters, but my knowledge of html and javascript is very limited. Is it possible to trigger the script by some kind of change-, click-, or mouseup-event?

    Edit: It might be this function:

    HTML Code:
    <script type="text/javascript">
    	var steal = { startFile: "avanzabank", env: "production", loaded: ['avanzabank/production.css'], production: "/js/jmvc/avanzabank/production.js?ver=r90645.10" }
    </script>

  3. #3
    Quote Originally Posted by Sandstedt
    [vba]IE(0).Document.getElementById("list").SelectedIndex = 2
    [/vba]
    That should work, but why are you using an array, IE(0)? Only a single IE object should be needed -
    [vba]
    IE.Document.getElementById("list").SelectedIndex = 2
    [/vba] - unless you are using an array of InternetExplorer objects. Post your code in full if you want more help.

    From what I understand, the dropdown list should trigger a javascript function but is unable to do so when I change its value in VBA.
    No, looking at the HTML source, there is no onclick or other event handler in the <select id="list" ...> element, so clicking it manually or by VBA doesn't trigger any Javascript function.

  4. #4
    Quote Originally Posted by Crocus Crow
    That should work, but why are you using an array, IE(0)? Only a single IE object should be needed -
    [vba]
    IE.Document.getElementById("list").SelectedIndex = 2
    [/vba] - unless you are using an array of InternetExplorer objects. Post your code in full if you want more help.
    I was working with several IE objects earlier, hence the array.

    Quote Originally Posted by Crocus Crow
    No, looking at the HTML source, there is no onclick or other event handler in the <select id="list" ...> element, so clicking it manually or by VBA doesn't trigger any Javascript function.
    Ok, how does the website react to my mouseclick? I don't understand why the website won't reload the page when my VBA code changes the listbox value.

  5. #5
    In the HTML source, there are some connections to the javascript(?) file steal.production.js

    I opened this file in Chrome and created event listener breakpoints, and then manually changed the dropdown list value. This activated the "change" control, and led me to the following code in the .js-file:

    HTML Code:
    a:a.replace(B,"mouseenter$1 mouseleave$1")};h.event={add:function(b,c,d,e,f){var g,k,l,j,s,n,m,p,o;if(!(b.nodeType===3||b.nodeType===8||!c||!d||!(g=h._data(b)))){if(d.handler){m=d;d=m.handler}if(!d.guid)d.guid=h.guid++;l=g.events;if(!l)g.events=l={};k=g.handle;if(!k){g.handle=k=function(b){return typeof h!=="undefined"&&(!b||h.event.triggered!==b.type)?h.event.dispatch.apply(k.elem,arguments):a};k.elem=b}c=h.trim(fa(c)).split(" ");for(g=0;g<c.length;g++){j=ba.exec(c[g])||[];s=j[1];n=(j[2]||"").split(".").sort();
    Is it safe to say then that there is a javascript function at work when I change the dropdown list?

  6. #6
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    below code works fine for me

    [vba]
    IE.Document.getElementById("list").selectedIndex = 8
    IE.Document.getElementById("list").FireEvent ("onchange")
    [/vba]

  7. #7
    Quote Originally Posted by mohanvijay
    below code works fine for me

    [vba]
    IE.Document.getElementById("list").selectedIndex = 8
    IE.Document.getElementById("list").FireEvent ("onchange")
    [/vba]
    That's great! I wonder why my code fails. The dropdown list changes value but the onchange-event doesn't trigger anything. Can you find any errors?

    [VBA]
    Sub UpdateList()
    Dim IE As Object

    lng_Sleep = 500

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    apiShowWindow IE.hwnd, SW_SHOWMINIMIZED
    Sleep lng_Sleep
    IE.navigate "https://www.avanzabank.se/aktier/lista"

    Do
    DoEvents
    Sleep lng_Sleep
    Loop While IE.ReadyState <> READYSTATE_COMPLETE

    IE.Document.getElementById("list").selectedIndex = 8
    IE.Document.getElementById("list").FireEvent ("onchange")
    End Sub[/VBA]

    I use IE9, if it's any help.
    Last edited by Sandstedt; 11-16-2012 at 09:53 AM.

  8. #8
    Solved!

    IE9 was the problem. Reverted to IE8, and modified the code to:

    [vba]ie.document.getElementByID("list").Focus
    ie.document.getElementByID("list").selectedIndex = 8
    ie.document.getElementByID("list").FireEvent ("onchange")[/vba]

    Didn't work without the .Focus-line. No idea why. Thanks everyone who tried to help.

  9. #9
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    1
    Location
    Hello everyone,

    I have the exact same problem with my code, a drop down conditionned by the drop down "PRODUCTID" doesn't update.
    But "focus" + "onchange" doesn't work...

    Here is my HTML code :

    <select data-mandatory="true" data-validation-type="3" class="field " name="PRODUCTID" data-field-name="engineModel" value="">						<option value="">Select</option>
    								<option>CFM56-2</option>
    								<option>CFM56-3</option>
    								<option>CFM56-5A</option>
    								<option>CFM56-5B</option>
    								<option>CFM56-5C</option>
    								<option>CFM56-7B</option>
    								<option>LEAP-1A</option>
    								<option>LEAP-1B</option>
    					</select>


    And my VBA code :

    For Each engine In IE.Document.GetElementsByName("PRODUCTID")(0).GetElementsByTagName("option")
        If engine.innerText = "LEAP-1A" Then
        engine.Focus
        engine.Selected = True
        engine.FireEvent ("onchange")
        End If
    Next



    Thanks a lot in advance (here is my first post ever !)

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Rafouf: This thread was last active in November 2012. Instead of trying to resurrect such an ancient thread, kindly start a new one. Thread closed.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •