Sign in to follow this  
Followers 0
KeshHERE

[ANSWERED]Why can't I change _IEFormElementSetValue without first giving it focus?

6 posts in this topic

#1 ·  Posted (edited)

This is site specific problem so try it out before wards because there is nothing wrong with code given below.

I have done several tasks like this using autoit before but it is first time that this happened to me! I wanted to get PDFs from this website by inputting date value and just pressing Submit button using autoit. Sounds simple but then this happened.

Using _IEFormElementSetValue I can change the date value but site doesn't register it as changed date for some reason. So even after pressing the Submit button using $oTag.click() in my program as you can see, It won't load any PDFs.

Then I found out that site registers the date value if I can give it focus first using .focus(), so i added it in my code and it worked as I wanted... Until I minimized the program.

My program works great only if it is on top with WinActivate() function but I have some other work to do and don't want to keep it open forever. I also tried to pop it open when it want to enter dates and then go back minimized but it gets annoying after sometime believe me..

SO my question is, Is there anything I can do to make it run minimized and without using focus?

Here is my code so far.. Don't worry about downloading PDFs I already have it worked out.

#include <String.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <Array.au3>
#include <Date.au3>
#include <Crypt.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
$oIE = _IECreateEmbedded()
$hGUI=GUICreate('Embedded', @DesktopWidth-50, @DesktopHeight-100,10,10)

$btSearch = GUICtrlCreateButton('GO', 500, 10, 60, 25)

$oIEobj=GUICtrlCreateObj($oIE, 10, 150, @DesktopWidth/2, @DesktopHeight-250)
GUISetState()

Global $URL='https://sanduskyoh.glyphreports.com'

While 1
    Local $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $btSearch

            Select
               Case StringInStr($URL,'glyphreport')
                  While 1
                     glyph()
                  WEnd
            EndSelect
   EndSwitch

    Sleep(500)
 WEnd






Func glyph()
   _IENavigate($oIE, $URL)

         Sleep(100)
         Local $oTags = _IETagNameGetCollection($oIE,'input')

            For $oTag In $oTags
;~             $oTag= _IEGetObjById($oIE,'startdatepicker')
;~             If Not @error Then
;~                $oTag.focus
;~                $oTag.value='10/01/2017'
;~             EndIf
;~             $oTag= _IEGetObjById($oIE,'enddatepicker')
;~             If Not @error Then
;~                $oTag.focus
;~                $oTag.value='10/05/2017'
;~             EndIf
               If $oTag.GetAttribute('id')="startdatepicker" Then
                  Sleep(100)
                  $oTag.focus
                  _IEFormElementSetValue($oTag, '10/01/2017')
               EndIf
               If $oTag.GetAttribute('id')="enddatepicker" Then
                  Sleep(100)
                  $oTag.focus
                  _IEFormElementSetValue($oTag, '10/04/2017')
               EndIf
            Next

         Sleep(100)
         Local $oTags= _IETagNameGetCollection($oIE,'span')

            For $oTag in $oTags
               If $oTag.innerText='Upload Date' Then
                  $oTag.click()
               EndIf
            Next

         Sleep(100)

         Local $oTags= _IETagNameGetCollection($oIE,'button')

            For $oTag in $oTags
               If $oTag.GetAttribute('id')='reportDateTypeSearchButton' Then
                  $oTag.click()
               EndIf
            Next

Sleep(100000)
EndFunc

Ignore some Include functions.. 

And here is input box html

<input id="startdatepicker" style="width: 100%;" placeholder="Pick Start Date" data-role="datepicker" type="text" class="k-input" role="combobox" aria-expanded="false" aria-owns="startdatepicker_dateview" aria-disabled="false" aria-readonly="false">

nothing suggest invoke onclick i think..

As you can see I also tried using _IEGetObjById($oIE,'startdatepicker') and $oTag.value='10/01/2017', But still it doesn't work minimized. I want it working in background.

Try it out without $oTag.focus first and you will see that you can't click Submit button(because site doesn't know that there are dates in box already written) even manually and no PDFs appear, But if you just click on each date box(after program sets the data value of those boxes without focus) manually and then click on Submit button it works.

 

P.S. - It does change the value inside the date boxes but Submitting doesn't work unless I use focus with it.

Autoit Glyph.au3

 

 

 

 

[ANSWER]

WORKING SCRIPT:-

There were three distinct events that needed to be fired :)

#include <String.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <Array.au3>
#include <Date.au3>
#include <Crypt.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
$oIE = _IECreateEmbedded()
$hGUI = GUICreate('Embedded', @DesktopWidth - 50, @DesktopHeight - 100, 10, 10)
$btSearch = GUICtrlCreateButton('GO', 500, 10, 60, 25)
$oIEobj = GUICtrlCreateObj($oIE, 10, 150, @DesktopWidth / 2, @DesktopHeight - 250)
GUISetState()

While True

    Local $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btSearch
            glyph()
    EndSwitch

WEnd


Func glyph()

    _IENavigate($oIE, 'https://sanduskyoh.glyphreports.com')

    $oStartDatePicker = _IEGetObjById($oIE, "startdatepicker")
    $oStartDatePicker.value = '10/01/2017'
    $oStartDatePicker.fireEvent("onfocus")
    $oStartDatePicker.fireEvent("onkeydown")
    $oStartDatePicker.fireEvent("onblur")

    $oStopDatePicker = _IEGetObjById($oIE, "enddatepicker")
    $oStopDatePicker.value = '10/04/2017'
    $oStopDatePicker.fireEvent("onfocus")
    $oStopDatePicker.fireEvent("onkeydown")
    $oStopDatePicker.fireEvent("onblur")

    Sleep(100)

    Local $oTags = _IETagNameGetCollection($oIE, 'span')
    For $oTag In $oTags
        If $oTag.innerText == 'Upload Date' Then
            $oTag.click
            ExitLoop
        EndIf
    Next

    Sleep(100)

    $oBtn = _IEGetObjById($oIE, "reportDateTypeSearchButton")
    $oBtn.click

EndFunc   ;==>glyph

 

Edited by KeshHERE
Answer

Share this post


Link to post
Share on other sites



#2 ·  Posted

You should check the HTML code. Most likely you have to invoke onclick or other events to update the value.

Share this post


Link to post
Share on other sites

#3 ·  Posted

<input id="startdatepicker" style="width: 100%;" placeholder="Pick Start Date" data-role="datepicker" type="text" class="k-input" role="combobox" aria-expanded="false" aria-owns="startdatepicker_dateview" aria-disabled="false" aria-readonly="false">

 

nothing suggest invoke onclick i think..

Share this post


Link to post
Share on other sites

#4 ·  Posted

3 hours ago, Juvigy said:

You should check the HTML code. Most likely you have to invoke onclick or other events to update the value.

<input id="startdatepicker" style="width: 100%;" placeholder="Pick Start Date" data-role="datepicker" type="text" class="k-input" role="combobox" aria-expanded="false" aria-owns="startdatepicker_dateview" aria-disabled="false" aria-readonly="false">

 

nothing suggest invoke onclick i think..

Share this post


Link to post
Share on other sites

#5 ·  Posted

There are jQuery events attached to the element. You can see this by using the Dom Explorer in the Developer Tools. You could try the following to see if triggering the jQuery change event will resolve the issue for you.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

17 minutes ago, Danp2 said:

There are jQuery events attached to the element. You can see this by using the Dom Explorer in the Developer Tools. You could try the following to see if triggering the jQuery change event will resolve the issue for you.

 

Thank you very much I found the solution as well :) I will attach the answer script at the end of my que :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0