Jump to content

Impossible to open ComboBox in IE (no Control functions allowed)


Ebola57
 Share

Recommended Posts

Hi community

I rewrote my problem for a better understanding and posted scripts that I allready tried

To sum up, I am able to do what I want on this page (ie : write in input, wait for the search engine result, click on button aso..., BUT not open combo box nor validate typed text
And this part is VERY important to me as I need t hide the browser (If visible I can manage this with Send () or ControlSend () )

Local $hIE = WinGetHandle ( "[CLASS:IEFrame]", {confidential} )
Local $oIE = _IEAttach( $hIE, "hwnd" )
Local $oDoc = _IEDocGetObj ( $oIE )

Local $sTagName = "select"
Local $sAttr1 = "name"
Local $sVal1 = "nature_du_stock_matriel_00"
Local $sNat = "ENEDIS"
Local $oItems

; Doesn't work
Local $oTagCollection = $oDoc.GetElementsByTagName ( $sTagName )
For $oTag In $oTagCollection
    If StringInStr ( $oTag.GetAttribute ( $sAttr1 ), $sVal1 ) > 0 Then
            Local $oItems = $oTag.Options
            For $oItem In $oItems
                If $oItem.Value == $sNat Then
                    $oItem.Selected = True
                    $oItem.FireEvent ( "OnChange" )
                    $oItem.FireEvent ( "OnClick" )
                    ExitLoop
                EndIf
            Next
        ;EndIf
    EndIf
Next

Local $sTagName = "input"
Local $sAttr1 = "aria-label"
Local $sVal1 = "Nature du stock matériel"
Local $sNat = "ENEDIS"

; Partial work, as shown in picture, but not what I need ( combobox opened, values validated )
Local $oTagCollection = $oDoc.GetElementsByTagName ( $sTagName )
For $oTag In $oTagCollection
    If StringInStr ( $oTag.GetAttribute ( $sAttr1 ), $sVal1 ) > 0 Then
        $oTag.Focus ( ) ; Works, as shown in picture
        $oTag.Click ( ) ; Does nothing on ALL tags
    EndIf
Next

; Nothing happens, tried an ALL tags
Local $oTagCollection = $oDoc.GetElementsByTagName ( $sTagName )
For $oTag In $oTagCollection
    If StringInStr ( $oTag.GetAttribute ( $sAttr1 ), $sVal1 ) > 0 Then
        $oTag.Click
        $oTag.FireEvent ( "OnChange" )
        $oTag.FireEvent ( "OnClick" )
    EndIf
Next

Got this in mind as a way of solution but don't really what to typas as  "node"

$oTag.FireEvent.KeyDown ( {DOMnode}, "{ key: 'Enter', code: 13 }" )

Also noticed that IE >= 9 may have differnte way of managing [ENTER] keypress as said here https://stackoverflow.com/questions/9714527/why-does-fireevent-not-work-in-ie9

But I wasn't able yet to translate it in autoit script

Tried this, with no effect, either on <a> tag or <input>

Local $oEvent = $oDoc.CreateEvent ( "HTMLEvents" )
$oEvent.InitEvent ( "change", True, False )
$oTag.DispatchEvent ( $oEvent )

Below the HTML source of the incriminated part

Any help, way of search or solution would be highly appreciated, as I am really stuck on this problem

Regards

Sans titre.png

Edited by Ebola57
Link to comment
Share on other sites

Indeed, but I forgot this way, as I was unable to catch the id / tag of the form

Since then I wrote a function that catch the "form" by attribute + propertie, going to try the "right" way again

As information this web page is taken from a ServiceNOW instance customized for my firm

Here the code displaying the form tag

Going to try again with your way and be back
Form.thumb.JPG.c6df799f4bd61e8c11d97bee673fb35b.JPG

Link to comment
Share on other sites

This code leads me to the result captured in screenshot

$hIE = WinGetHandle ( "[CLASS:IEFrame]","" )
WinActivate ( $hIE )
$oIE = _IEAttach( $hIE, "hwnd" )
Local $aForm = _IEGetObjBy2AttributesAnd2Values ( $oIE, "form", "class", "ng-pristine ng-valid ng-valid-maxlength", "role", "form", 5000 )
Local $oSelect = _IEFormElementGetObjByName($aForm [0], "unite_d_oeuvre_00")
_IEAction ( $oSelect, "focus" )
_IEFormElementOptionSelect ( $oSelect, "CNIP-A03 : Remplacement poste de travail", 1, "byText" )

_IEGetObjBy2AttributesAnd2Values is a custom function that catch the form object when it has neither id nor name, 5000 is a timeout value

The box is selected, but doesn't scroll or select any item :/

the ending point is still the same, i can't interract with such combo box without having to send a ControlSend command, that I'd like to get rid off


 

Form_2.JPG

Edited by Ebola57
Link to comment
Share on other sites

Can you run the following in Scite and show us the results from the Output panel?

$hIE = WinGetHandle ( "[CLASS:IEFrame]","" )
$oIE = _IEAttach( $hIE, "hwnd" )
Local $aForm = _IEGetObjBy2AttributesAnd2Values ( $oIE, "form", "class", "ng-pristine ng-valid ng-valid-maxlength", "role", "form", 5000 )
Local $oSelect = _IEFormElementGetObjByName($aForm[0], "nature_du_stock_matriel_00")
_IEFormElementOptionSelect( $oSelect, "ENEDIS")
_IEFormElementOptionSelect( $oSelect, "GRDF", 1, "byText")

 

Link to comment
Share on other sites

Sure ! but ... As this unoptimised function is no more, rewrote some code that should do equivalent to your code  (if I am right)

 

#include <IE.au3>

Local $hIE = WinGetHandle ( "[CLASS:IEFrame]", "MyUrl" )
WinActivate ( $hIE )
Local $oIE = _IEAttach( $hIE, "hwnd" )
Local $oDoc = _IEDocGetObj ( $oIE )
Local $oForm = _IEFormGetObjCustomWay ( $oDoc )
Local $oSelect = _IEGetObjByName ( $oForm, "nature_du_stock_matriel_00" )
_IEFormElementOptionSelect( $oSelect, "ENEDIS")
_IEFormElementOptionSelect( $oSelect, "GRDF", 1, "byText")

Func _IEFormGetObjCustomWay ( $oDoc )
    Local $oForms = $oDoc.GetElementsByTagName ( "form" )
    If IsObj ( $oForms ) Then
        For $Form In $oForms
            If $Form.GetAttribute ( "class" ) == "ng-pristine ng-valid ng-valid-maxlength" And $Form.GetAttribute ( "role" ) == "form" Then
                Return SetError (0 ,0, $Form )
            EndIf
        Next
    Else
        Return SetError (1 ,0, "Not a form collection" )
    EndIf
EndFunc

Such code does nothing in my IE session and here's Scite output

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\path\Tests autoit forum.au3" /UserParams    
+>17:40:00 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:0000040C  OS:WIN_81/  CPU:X64 OS:X64  Environment(Language:040C)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.5)  from:C:\path\Tests autoit forum.au3
+>17:40:00 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\path\Tests autoit forum.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>17:40:01 AutoIt3.exe ended.rc:0
+>17:40:01 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.156

 

Link to comment
Share on other sites

Link to comment
Share on other sites

I never had such symptoms, but in this case, the HTML is somehow heavy and complex

What I learnt is there's some Javascript from an Angular Framework

On other combo box, when 'click' or 'Eneter' is pressed it générates a serach engine where i ahve to pick up the value that fills then the input box

Got the same problem on this item, everything is possible but not 'Enter' nor 'click'

Link to comment
Share on other sites

3 minutes ago, Nine said:

"nature_du_stock_matriel_00"  there is a fault in there.  Shouldn't that be ""nature_du_stock_matériel_00" ?

nvm misread it :/

Indeed, in French (native language) it should be 'materiel', but there's an "official" typo error Inside the code ...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...