HTML date picker without an input field. use VBA to fire update event

Good,

A simple task with a difficult solution (currently)

There is a page with a choice of date and time. The date picker does not have an html input element, but I can access it using InnerText. No problem using InnerText to put dates in and out of dates in

The problem arises as such:

When dates are entered manually , a โ€œformโ€ appears that updates live when the user selects dates and displays only data within this date range. When done programmatically , there is no live update of the "form"

Trying so far:

Set document = objIE.document

With document
    .getElementsByClassName("controls").Item(0).Focus
    .getElementsByClassName("select-daterange").Item(0).Focus
    .getElementsByClassName("select-datepicker from").Item(0).Focus
    .getElementsByClassName("date-label").Item(0).innerText = "June 1, 2017"
    .getElementsByClassName("date-label").Item(1).innerText = "June 5, 2017"
End With

Rate any community recommendations!

Here is an example of selecting a date:

No-input Date Picker

+4
1

, Javascript- VBA fireevent.

Mozilla Dev - EventTarget.fireEvent

.

Option Explicit

Sub Test()
    '* Tools->References->Microsoft HTML Object Library
    '* Tools->References->Microsoft Internet Controls

    Dim ie As SHDocVw.InternetExplorerMedium
    Set ie = New SHDocVw.InternetExplorerMedium


    ie.Visible = True
    ie.navigate "n:\TestWebOnChangeManually.html"

    Dim obj As Object

    Stop '* i use this pause to dismiss Allow Block Content footer warning message
    Dim dom As MSHTML.HTMLDocument
    Set dom = ie.document

    Dim textSource As MSHTML.HTMLInputElement
    Set textSource = dom.getElementById("source")

    textSource.innerText = "poked"

    'https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/fireEvent
    '* not sure what to place in second parameter
    textSource.FireEvent "onchange", Nothing


End Sub

html

<html>
<head/>

<body>

<input id="source" type="text" onChange="MyChange('source')"></input>

<input id="someOtherControlToFocusSwitchTo" type="text" value="foo"></input>


<script>
    function MyChange(eleId)
    {
        if (eleId)
        {
            var ele = document.getElementById(eleId);
            if (ele) {
                alert(ele.value);
            }
        } else
        {
            alert("MyChange fired with no param");
        }

    }

</script>
</body>
</html>

, -, , dispatchEvent , SO FireEvent IE11, . VBA javascript, SO onchange ?, SO JavaScript?

' Fire the onChange event...
Dim objEvent
Set objEvent = doc.createEvent("HTMLEvents")
objEvent.initEvent "change", False, True
e.dispatchEvent objEvent

, , .

+1

Source: https://habr.com/ru/post/1682406/


All Articles