Jump to content

Recommended Posts

Posted

hi guys , i try to automate  , a shipment , in this site , with this code 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <IE.au3>
#include <Array.au3>
#include <INet.au3>

Global $iCont_truck = 0, $iGTimeToCeckTruck = 1000, $iGTimeOutTruck = 1000


If ProcessExists("iexplore.exe") Then ; Check if the internet esplorer process is running.
    ProcessClose("iexplore.exe")
EndIf

Global $oIE = _IECreate("https://www.truckpooling.it/", 0, 1, 1, 1) ; <--- 0011 invisible explorer  <--- 0111 visible explorer
_IELoadWait($oIE, $iGTimeToCeckTruck, $iGTimeOutTruck)
Local $oBtns = $oIE.document.GetElementsByTagName("span")
For $oBtn In $oBtns
    $id = String($oBtn.classname())
    ConsoleWrite($id & @CRLF)
    If $id = "select2-selection__rendered" Then
        _IEAction($oBtn, "click")
        _IEFormElementSetValue($oBtn, "fucecchio")
        _IEAction($oBtn, "click")
    EndIf
Next

a combobox  for insert city not  work someone could help me ?? thankz 

Posted

That is a complex task due to the fact that it doesn't involve a standard select element and instead uses multiple elements and jQuery events. If I were trying to do this, I would use @Chimp's jQuerify routine to gain access to the jQuery object. With that, you should be able to trigger the events to mimic a user clicking the the element, entering text, selecting an item from the list, etc.

Another option would be to use IUIAutomation.

Posted

Here is an example without Danp2's suggestion.

#include <IE.au3>

Local $oIE = _IECreate("https://www.truckpooling.it/", 0, 0)


Local $oObject1 = _IEGetObjByClass($oIE, "select2-selection select2-selection--single")
ConsoleWrite(IsObj($oObject1) & @CRLF)
_IEAction($oObject1, "focus")
ControlSend(_IEPropertyGet($oIE, "hwnd"), "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{ENTER}")

Local $oObject2 = _IEGetObjByClass($oIE, "select2-search__field")
ConsoleWrite(IsObj($oObject2) & @CRLF)
_IEAction($oObject2, "focus")

ControlSend(_IEPropertyGet($oIE, "hwnd"), "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "00010")
Sleep(2000) ;wait load
ControlSend(_IEPropertyGet($oIE, "hwnd"), "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{ENTER}")
WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_SHOW)

MsgBox(0, "", "00010 should be selected")


Func _IEGetObjByClass(ByRef $o_object, $s_Class, $i_index = 0)
    If Not IsObj($o_object) Then
        __IEConsoleWriteError("Error", "_IEGetObjByClass", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    If Not __IEIsObjType($o_object, "browserdom") Then
        __IEConsoleWriteError("Error", "_IEGetObjByClass", "$_IEStatus_InvalidObjectType")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    Local $i_found = 0
    ;
    $o_tags = _IETagNameAllGetCollection($o_object)
    For $o_tag In $o_tags
        If String($o_tag.className) = $s_Class Then
            If ($i_found = $i_index) Then
                SetError($_IEStatus_Success)
                Return $o_tag
            Else
                $i_found += 1
            EndIf
        EndIf
    Next
    ;
    __IEConsoleWriteError("Warning", "_IEGetObjByClass", "$_IEStatus_NoMatch", $s_Class)
    SetError($_IEStatus_NoMatch, 2)
    Return 0
EndFunc   ;==>_IEGetObjByClass

 


Saludos

Posted

but now  the problem is , in the page i have 2 combo box identical , and if i want  set a second combo , how is possible to do that ? 

 

Posted

 

 

Change the instance Index

 

local $objectSecondInstace=_IEGetObjByClass($oIE, "select2-selection select2-selection--single",1)

 

Saludos

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
  • Recently Browsing   0 members

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