+ Reply to Thread
Results 1 to 16 of 16

Selecting an option in DOM(HTML, Javascript)

  1. #1
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Selecting an option in DOM(HTML, Javascript)

    I want this to select an option other than 'Intraday' here, so that the URL in the 'Download' button starts with 'https://www.oslobors.no/ob/servlets/excel?type=history&columns=DATE', and not 'https://www.oslobors.no/ob/servlets/excel?type=history&columns=TIME'. I manage to get it to change to '1 week' and highlight it, but it doesn't actually change the selection so that the URL/chart is changed.
    Please Login or Register  to view this content.
    Last edited by Woulter; 05-06-2018 at 01:35 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    That just needs an observation of the webpage, a beginner level demonstration as a starter :

    PHP Code: 
    Sub Demo1()
                 
    Dim oElt As Object
        With CreateObject
    ("InternetExplorer.Application")
                    .
    Navigate "https://www.oslobors.no/ob_eng/markedsaktivitet/#/details/STL.OSE/overview"
                    
    .Visible True
              
    While .Busy Or .ReadyState 4:  DoEvents:  Wend
              
    Do: Loop Until .Document.getElementsByTagName("SELECT").Length
            
    For Each oElt In .Document.getElementsByTagName("SELECT")
                  If 
    oElt.Options.Value "INTRADAY" Then
                     oElt
    .selectedIndex 1
                 Set oElt 
    Nothing
                     
    Exit For
                 
    End If
            
    Next
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Try this !

    It only changes what is shown in the 'select' tag/element, it does not change the URL in the button, or the time frame in the chart.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    Working on my side :

    PHP Code: 
    Sub Demo2()
                 
    Dim oElt As Object
        With CreateObject
    ("InternetExplorer.Application")
                    .
    Navigate "https://www.oslobors.no/ob_eng/markedsaktivitet/#/details/STL.OSE/overview"
                    
    .Visible True
              
    While .Busy Or .ReadyState 4:  DoEvents:  Wend
              
    Do: Loop Until .Document.getElementsByTagName("SELECT").Length
            
    For Each oElt In .Document.getElementsByTagName("SELECT")
                  If 
    oElt.Options.Value "INTRADAY" Then
                     oElt
    .Focus
                     CreateObject
    ("WScript.Shell").SendKeys "{DOWN}"
                 
    Set oElt Nothing
                     
    Exit For
                 
    End If
            
    Next
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    That's with a key, not DOM.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Selecting an option in DOM(HTML, Javascript)


    First one was via DOM but as you seems so smart, just run the JScript event procedure associated
    as you can observe using the webbrowser inner inspector tool …

  7. #7
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    What does this mean 'just run the JScript event procedure associated
    as you can observe using the webbrowser inner inspector tool
    …'?

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Selecting an option in DOM(HTML, Javascript)


    Inspect the element with the webbrowser tool …
    Or just stay with the easy way of my second demonstration.

    Or as you did not ever explain the final purpose, because often piloting IE is useless
    you may just need to reproduce the final request used as you can see again with the inspector tool,
    read inner help of your webbrowser or see on MSDN …
    Last edited by Marc L; 05-08-2018 at 08:50 AM.

  9. #9
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    What should I inspect?
    ob.png
    Sending keys requires that the browser is open and is the active window.
    I want this to select an option other than 'Intraday' here, so that the URL in the 'Download' button starts with 'https://www.oslobors.no/ob/servlets/excel?type=history&columns=DATE', and not 'https://www.oslobors.no/ob/servlets/excel?type=history&columns=TIME'.
    What 'inner help'?
    Where on 'MSDN'?

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Selecting an option in DOM(HTML, Javascript)


    As sending keys works !

    In your webbrowser exist help (so an inner one) and an inspector tool which can be called
    via right click (like inspect element, depends on the version) or via the F12 key …

    On recent webbrowsers you can directly inspect the JScript events linked to an element.

    Apply a classic tags web search like MSDN + other words like developer tools.
    All Microsoft help is on MSDN whatever Office, VBA, IE, VBScript, Windows, …


  11. #11
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    Sending keys is not the DOM.

    The screenshot is of the 'inspector tool'.

    I have searched, read MSDN/forums etc. Question is what exactly should I read, is it possible to change the URL via DOM?

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Selecting an option in DOM(HTML, Javascript)


    You can't change the URL as it is a JScript event which updates the webpage if I'm not wrong …
    So outside DOM so the easy VBA way is to send keys if piloting IE is necessary or to find & execute the JScript event
    or to leave VBA for a better Web language …

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an option in DOM(HTML, Javascript)

    It's done like this, but I strongly discourage this approach:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    Thank you(didn't see your post until today), why do you discourage it?
    Last edited by Woulter; 06-07-2018 at 12:49 PM.

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Selecting an option in DOM(HTML, Javascript)

    Because automating ie is very, very slow. It's also much more fragile than the proper approach

  16. #16
    Registered User
    Join Date
    03-26-2014
    Location
    Norway
    MS-Off Ver
    Microsoft 365 MSO (Version 2403 Build 16.0.17425.20124) 64-bit
    Posts
    33

    Re: Selecting an option in DOM(HTML, Javascript)

    Doing it manually is even slower!

    'proper approach'?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 13
    Last Post: 03-30-2017, 06:45 AM
  2. HTML Select Multiple Values in Option Menu
    By San_K in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2015, 03:38 PM
  3. Select option in HTML drop down list
    By JohnsonJiang in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-15-2014, 03:28 PM
  4. Retrieve HTML <option> Values
    By danger_mouse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-29-2013, 04:20 PM
  5. Replies: 3
    Last Post: 02-02-2012, 12:18 PM
  6. Best option for Html
    By tj32 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2008, 04:46 PM
  7. Navigating between option buttons is not selecting the option
    By Ramana in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-03-2005, 10:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1