Jump to content

taylansan

Active Members
  • Posts

    102
  • Joined

  • Last visited

Reputation Activity

  1. Like
    taylansan got a reaction from SOLVE-SMART in WebDriver: I can't find an element with h1 title   
    That was.. really good explanation. Thank you
  2. Thanks
    taylansan reacted to SOLVE-SMART in WebDriver: I can't find an element with h1 title   
    Hi @taylansan ðŸ‘‹ ,
    please notice âš  I assume such a structure:
    you use _WD_FindElement() in the multi element way. The fifth parameter is set to true which means you want to get all occurences of the <h1> elements (with the specific text).
    1. Either you change your XPath to only search the first element like
    (//h1[contains(text(),'Welcome to BSS')])[1] or 2. simply set false as fifth parameter
    _WD_FindElement($sSession, $mConfig.LocatorStrategy, $sSelector, Default, False) or 3, without the fifth parameter because the default value is false
    _WD_FindElement($sSession, $mConfig.LocatorStrategy, $sSelector, Default) ... and try again 🙂 .
    -----------------------------------------
    âš  In case you are searching within an iframe, you first have to enter the frame and do your locator strategy (search) their.
    Func _EnterIFrame($sSelector) _WD_FrameEnter($sSession, _FindElement($sSelector)) EndFunc Best regards
    Sven
  3. Like
    taylansan reacted to ioa747 in Check if a key (ctrl, alt, shift) is already down   
    #include <Misc.au3> Global $hDLL = DllOpen("user32.dll") While 1 If _IsPressed("10", $hDLL) Then ;10 SHIFT key ConsoleWrite("Shift Key is down" & @CRLF) While _IsPressed("10", $hDLL) ;10 SHIFT key If _IsPressed("12", $hDLL) Then ;12 ALT key ConsoleWrite("SHIFT + ALT is down" & @CRLF) ElseIf _IsPressed("11", $hDLL) Then ;11 CTRL key ConsoleWrite("SHIFT + CTRL is down" & @CRLF) EndIf Sleep(150) WEnd ConsoleWrite("Shift Key is up" & @CRLF) EndIf Sleep(10) WEnd  
  4. Like
    taylansan reacted to Danp2 in Do the functions have priority over ConsoleWrite?   
    From the help file --
    So that explains where the 0 comes from. I believe I addressed your other confusion in my prior post, so maybe you could elaborate on why you are still confused.
  5. Sad
    taylansan reacted to AspirinJunkie in Exact division but can't satisfy the condition   
    Because it is not exactly 0.5.
    It is only rounded on output, so you don't see this.
    Consolewrite basically makes an implicit string() around the number variable to be output.
    And this has the effect of rounding if the difference occurs after the 14th decimal place. 
    Modify your output line as follows to avoid this implicit rounding:
    ConsoleWrite(StringFormat("Output will be: %d %d --> %.17f\n", $x, $y, $result))  
  6. Like
    taylansan reacted to ioa747 in RunWait calling another script, but can't see ConsoleWrite in the subscript   
    the best i know is by @Gianni
    I hope this helps
  7. Like
    taylansan reacted to Trong in DllCall to GetFileSize   
    Might be superfluous, but I can add a WINAPI function that checks the size with a single Function:
    Global $iFileSize, $iFilePath = @AutoItExe ; "C:\Program Files (x86)\AutoIt3\autoit3.exe" ConsoleWrite(">File to Check: " & $iFilePath & " | FileExists=" & FileExists($iFilePath) & " " & @CRLF) ;Example 1 = Built-in functions $iFileSize = FileGetSize($iFilePath) ConsoleWrite("+ FileSize: " & $iFileSize & @CRLF) ;Example 2 = WinAPI DllCall $iFileSize = _WinAPI_GetFileSize($iFilePath) ConsoleWrite("- FileSize: " & $iFileSize & @CRLF) Func _WinAPI_GetFileSize($sFileNameOrHandle) Local $hFile = 0, $aCall = 0 If VarGetType($sFileNameOrHandle) = 'Ptr' And (Not FileExists($sFileNameOrHandle)) Then $hFile = $sFileNameOrHandle Else Local Const $iOpenExist = 3, $iShareRead = 0x00000001, $iAccessRead = 0x80000000, $iAttributes = 0, $tSecurity = 0 $aCall = DllCall("kernel32.dll", "handle", "CreateFileW", "wstr", $sFileNameOrHandle, "dword", $iAccessRead, "dword", $iShareRead, "struct*", $tSecurity, "dword", $iOpenExist, "dword", $iAttributes, "ptr", 0) If @error Or ($aCall[0] = Ptr(-1)) Then Return SetError(1, @extended, 0) $hFile = $aCall[0] EndIf $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) If @error Or Not $aCall[0] Then Return SetError(2, @extended, 0) Return $aCall[2] EndFunc ;==>_WinAPI_GetFileSize  
  8. Like
    taylansan reacted to Danp2 in DllCall to GetFileSize   
    @taylansanWhat's your obsession with using DLLCall? Also, how to do you that FileGetSize isn't calling the same API behind the scenes?
    Example 3 isn't valid because you can't use a file handle with FileGetSize Examples 4 & 5 will work if adjust as follows -- ;Example 4 $hFile = _WinAPI_CreateFile(@AutoItExe, 2, 2, 2) ;### Debug CONSOLE ↓↓↓ ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hFile = ' & $hFile & @CRLF & '>Error code: ' & @error & @CRLF) $iFileSize = 0 $iFileSize = _WinAPI_GetFileSizeEx($hFile) ConsoleWrite("Example 4: " & $iFileSize & @CRLF) ;Example 5 $iFileSize = 0 Local $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) ConsoleWrite("Example 5: " & $aCall[2] & @CRLF) _WinAPI_CloseHandle($hFile)  
  9. Like
    taylansan reacted to pixelsearch in DllCall to GetFileSize   
    @taylansan If you read carefully @Danp2 last script, then you should have the answers to your 3 questions.
    By using the  _WinAPI_CreateFile function that returns the correct handle.
    If you look carefully, I also created a new file only in Script 1, but not in script 2, where I wrote just before the script :
    2nd script, with an already existing file on disk (your case) By the way, it's not because the function is called _WinAPI_CreateFile that it always creates a new file. I know it sounds strange but this function works also with existing files stored on disk. Maybe Microsoft could have given a better name to the function, avoiding the word "Create" in it. Look at the explanations found on msdn :
    CreateFile function : Creates OR opens a file or I/O device [...]  
    Danp2 answered to that concerning your example 3, in his own words : "you can't use a file handle with FileGetSize" . Always look carefully at the help file to make sure when you need a file string name, or a file handle
    Yes you do need to open it but don't be scared of this, because _WinAPI_CreateFile opens it immediately, even if it's several GB.
    Danp2 answered to that, in his own words : "Also, how do you know that FileGetSize isn't calling the same API behind the scenes?"  (e.g. CreateFile)
    Now let's go back to my last post (the "Edit post") where I asked at the end :
    I just did interesting tests concerning the _WinAPI_GetFileSize (using my Script #2 found in a post above) and the results are crystal clear. First the resulting pic :

    As you can see, the assumption was correct : $aRet[2] must be checked in case the file size is >= 4GB
    If you don't check it, then you'll have correct results for a file whose size is < 4GB - 2 bytes, but as soon as a file size is >= 4GB, then $aRet[2] is required to retrieve the  high-order Dword (remember it was scripted dword* with a star, e.g. to retrieve in the resulting array a value returned by the system. Without the star it won't have retrieved anything and $aRet[2] would have been = 0 in all pics !)
    In 3 out of 4 pics, $aRet[2] = 1 means that 4GB need to be added to $aRet[0] . If $aRet[2] was equal to 2, then 8GB would have needed to be added to $aRet[0] (which contains bytes), so the calculation of an accurate result isn't that hard to do. I won't do it here and keep the precedent script #2 "as-is" because of all explanations that followed the post, also because noone should use this non AutoIt  _WinAPI_GetFileSize function when there are better, easier and safer ways to retrieve a file size. But it was interesting to dig in it and understand better how the function works. Thanks to you for creating the thread !
    For the record, to create  all these big files in a snap, I typed fsutil at the command prompt... but that's another story 
  10. Like
    taylansan got a reaction from pixelsearch in DllCall to GetFileSize   
    @Danp2 Yeah, FileGetSize will get the file size. But I want to use DllCall to get the size. So, maybe we can try _WinAPI_GetFileSizeEx
    @pixelsearch In the help documentation, you are creating a new file to be used in _WinAPI_GetFileSizeEx. 
     
    Let's say, I want to get the size of "autoit3.exe" which is around 900kb. This is stored (in my computer) in "C:\Program Files (x86)\AutoIt3\autoit3.exe" and we have a shortcut to reach this easily: @AutoItExe
    So, I tried this: 1 + 2 is working as expected because they are using FileGetSize. But I wanted to make it work for 3 + 4 + 5. So, I tried several random options: 
    #include <WinAPIFiles.au3> ;Example 1 = OK Local $iFileSize = FileGetSize(@AutoItExe) ConsoleWrite("Example 1: " & $iFileSize & @CRLF) ;Example 2 = OK $iFileSize = 0 $iFileSize = FileGetSize("C:\Program Files (x86)\AutoIt3\autoit3.exe") ConsoleWrite("Example 2: " & $iFileSize & @CRLF) ;Example 3 = NOT OK Local $hFile = FileOpen(@AutoItExe) ;OR Local $hFile = FileOpen("C:\Program Files (x86)\AutoIt3\autoit3.exe") $iFileSize = 0 $iFileSize = FileGetSize($hFile) ConsoleWrite("Example 3: " & $iFileSize & @CRLF) ;Example 4 = NOT OK $iFileSize = 0 $iFileSize = _WinAPI_GetFileSizeEx($hFile) ConsoleWrite("Example 4: " & $iFileSize & @CRLF) ;Example 5 = NOT OK $iFileSize = 0 Local $aCall = DllCall("kernel32.dll", "bool", "GetFileSizeEx", "handle", $hFile, "int64*", 0) ConsoleWrite("Example 5: " & $aCall[2] & @CRLF) FileClose($hFile) My output is as the following: 
    Example 1: 946776 Example 2: 946776 Example 3: 0 Example 4: -1 Example 5: 0 So, I think I couldn't send handle $hFile correctly. So: 
    How can I send "C:\Program Files (x86)\AutoIt3\autoit3.exe" or @AutoItExe as the correct handle?  I used FileOpen() to get the handle, is this the place where I did wrong? Should I use a different function to open and get the file? Which one is it? What if the file I'm looking for is a big file, like few GB? Do I still need to open them to assign as a handle? Because FileGetSize() doesn't use a handle.   
    Please note the same as before; the goal for me is to use the DllCall function, not to get the file size by using FileGetSize(). 
  11. Like
    taylansan reacted to pixelsearch in DllCall to GetFileSize   
    Edit (placed on purpose in a new post) :
    I think the function _WinAPI_GetFileSize() as scripted just above would return a correct result only if the file size is < 4GB (maximum of Dword) so $aRet[0] will contain the correct file size.
    If the file size is > 4GB, then the high-order doubleword of the file size will be returned to the 2nd parameter of the function, e.g $aRet[2] which was scripted like this :
    "dword*", 0 Which means, if the file size is > 4GB, then we should take care of $aRet[2] AND $aRet[0] to calculate the correct size (!?)
    Reminder: Msdn notes when GetFileSize function succeeds :
    GetFileSize function Return value : If the function succeeds, the return value is the low-order doubleword of the file size, and, if lpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter. Maybe that's the reason why GetFileSize shouldn't be used and GetFileSizeEx should be preferred, as GetFileSizeEx deals in a simpler way when files have a size > 4GB . Also in Msdn words :
    GetFileSize function Retrieves the size of the specified file, in bytes. It is recommended that you use GetFileSizeEx. [...] Could a DllCall guru share his comments about this, especially the part  $aRet[2] AND $aRet[0]  discussed just above ?
    Thanks 
     
  12. Thanks
    taylansan reacted to TheXman in GUICtrlCreateList Example   
    You can use _GUICtrlListBox_SetCurSel() to set the current selection to the last entry in the listbox and scroll it into view.
    #include <GuiListBox.au3> . . . Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") _GUICtrlListBox_SetCurSel($idMylist, _GUICtrlListBox_GetCount($idMylist) - 1)  
  13. Like
    taylansan reacted to Danp2 in WebDriver UDF - Help & Support (III)   
    SelectorsHub give a relative xpath of "//ytd-mini-guide-entry-renderer[@aria-label='Subscriptions']//a[@id='endpoint']", so I would try using that to see if it works.
  14. Thanks
    taylansan reacted to Danp2 in WebDriver UDF - Help & Support (III)   
    In the output you posted, it's looking for the actual webdriver (msedgedriver.exe). Have you installed that in your working directory?
    You'll need to unblock the file. Details copied from here --
     
  15. Like
    taylansan reacted to Danp2 in WebDriver UDF - Help & Support (III)   
    As the WebDriver UDF - Help & Support thread has grown too big, I started a new one.
    The prior thread can be found here.
  16. Thanks
    taylansan reacted to Nine in Finding process name or pid shown in windows   
    Here your Christmas gift early 
    #include <Constants.au3> #include <Array.au3> Opt("MustDeclareVars", 1) _CheckService() Func _CheckService() Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Service WHERE State = "Running"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object") If Not $colItems.count Then Exit MsgBox(0, "", "Service not found") Local $aService[$colItems.count][4], $i = 0 For $sItem In $colItems $aService[$i][0] = $sItem.Caption $aService[$i][1] = $sItem.PathName $aService[$i][2] = $sItem.ProcessId $aService[$i][3] = $sItem.Name $i += 1 Next _ArrayDisplay ($aService) EndFunc ;==>_CheckService HoHoHo !
  17. Like
    taylansan got a reaction from adegard in IE DOM Elements visual selector tool   
    Hi Chimp, 
    Yeah, now it works very fine. This is very handy and useful tool which makes automation a lot easier. 
    Thank you very much for providing this and update. 
  18. Thanks
    taylansan reacted to Gianni in IE DOM Elements visual selector tool   
    Hi @taylansan and also to all of you who have come to read ...
    after some debugging I've found the cause of the issue you reported.
    The 'subtle' problem was not in the javascript function that retrieves the CSS selector, it was instead caused by a "div" element that I injected into the page, to be used as an highlighter on the element where the right-click was performed.
    To highlight the right-clicked element, Instead of poisoning the page by injecting the div element, now I use an innocuous colored 5px dotted outline
    well, the "debuged" listing is now posted in first post replacing the previuos one.
    Bug reports, suggestion and improovements are welcome.
    Thank You
  19. Like
    taylansan reacted to Gianni in IE DOM Elements visual selector tool   
    The DOM allows to do anything with elements and their contents, but first we need to reach the corresponding DOM object, get it into a variable, and then we are able to modify it. *
    Well, this little tool (although it is not very nice aesthetically) allows you to get visually a "selector" usable to reference DOM objects.
    Once you have the "selector" of an element you can pass it to the javascript querySelector() function that will return a reference to that element.
    To use this tool you have to:
    1) open the web page you want to inspect into IE browser
    2) run this script (if it find more instances of IE running, it allows you to chose one)
    3) move the mouse over the browser. The "selector" of the element below the pointer is catched automatically while hovering. To copy the selector in the clipboard just right click on the element.
    As you can see, while hovering, the element pointed by the mouse is highlighted with a thin red dotted frame to allow you to better "take aim"
    when the selector is copied to the clipboard a little acoustic signal is emitted as a confirm, then you can paste it in your listing where you need it.
    I hope it can come in handy and save you time when you need to automate a site .... have fun (debugged on Sept. 30 2018)
    #include <IE.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; for _IsPressed (23 END key) Global $hDLL = DllOpen("user32.dll") ; following global variables are automatically updated by events from the browser ; ------------------------------------------------------------------------------------- Global $g_iMouseX, $g_iMouseY ; coordinates of the mouse while mooving over the browser Global $bCopySelector = False ; becomes True when you right click on wanted element ; ------------------------------------------------------------------------------------- Global $oIE = _Get_IE() ; get IE instance to inspect If IsObj($oIE) Then $hIE = _IEPropertyGet($oIE, "hwnd") WinActivate($hIE) _InspectElements() EndIf DllClose($hDLL) Exit Func _InspectElements() ; it uses the global variable $oIE as source ; --- set IE to interact with AutoIt --- Local $oDocument Do ; wait for document Sleep(250) $oDocument = $oIE.document Until IsObj($oDocument) Local $oWindow = $oDocument.ParentWindow ; create a reference to the javascript eval method ; in the body section of the dovument $oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; attach the $JSeval variable to the javascript eval method Local $JSeval Do $JSeval = Execute('$oIE.Document.body.JSeval') Until IsObj($JSeval) ; --------------------------------------------- ; Inject Javascript functions/elements to $oIE ; --------------------------------------------- ; Get the DOM path of an element (a CSS selector) ; ----------------------------------------------- ; This javascript function returns the CSS selector of the passed element. ; You can then use the returned path to get a reference to the pointed ; element by the QuerySelector() javascript function ; function copied from the following link: ; https://stackoverflow.com/questions/5728558/get-the-dom-path-of-the-clicked-a ; see answer by "Aleksandar Totic" (thanks to him) Local $sJScript = "" & _ " function getDomPath(el) {" & _ " if (!el) {" & _ " return;" & _ " }" & _ " var stack = [];" & _ " var isShadow = false;" & _ " while (el.parentNode != null) {" & _ " var sibCount = 0;" & _ " var sibIndex = 0;" & _ " for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {" & _ " var sib = el.parentNode.childNodes[i];" & _ " if ( sib.nodeName == el.nodeName ) {" & _ " if ( sib === el ) {" & _ " sibIndex = sibCount;" & _ " }" & _ " sibCount++;" & _ " }" & _ " }" & _ " var nodeName = el.nodeName.toLowerCase();" & _ " if (isShadow) {" & _ " nodeName += ""::shadow"";" & _ " isShadow = false;" & _ " }" & _ " if ( sibCount > 1 ) {" & _ " stack.unshift(nodeName + ':nth-of-type(' + (sibIndex + 1) + ')');" & _ " } else {" & _ " stack.unshift(nodeName);" & _ " }" & _ " el = el.parentNode;" & _ " if (el.nodeType === 11) {" & _ " isShadow = true;" & _ " el = el.host;" & _ " }" & _ " }" & _ " stack.splice(0,1);" & _ " return stack.join(' > ');" & _ " }" ; more infos here: https://www.kirupa.com/html5/finding_elements_dom_using_querySelector.htm ; Inject the above javascript function contained in the $sJScript variable into the document _JS_Inject($oIE, $sJScript) Local $_getDomPath ; a reference to call above function from AutoIt Do Sleep(250) $_getDomPath = $jsEval("getDomPath") Until IsObj($_getDomPath) ; ; ------------------- ; hook some IE events ; ------------------- Local $oEventObjects[2], $oEventsSource $oEventsSource = $oIE.document.documentElement ; element we want catch events from ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa769636(v=vs.85) $oEventObjects[0] = ObjEvent($oEventsSource, "_HTMLElementEvents2_", "HTMLElementEvents2") ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768283(v%3dvs.85) $oEventObjects[1] = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2") ; open a GUI where to show some element's properties ; -------------------------------------------------- Local $hGUIMain = GUICreate("Info", 500, 140, -1, -1, -1, $WS_EX_TOPMOST) Local $hProperties = GUICtrlCreateEdit("", 0, 0, 500, 140) GUICtrlSetFont(-1, 9, -1, -1, "Courier New") GUISetState() ;Show GUI ; -------------------------------------------------- ; --------- ; Main loop ; --------- Local $iMouseX, $iMouseY, $oElement, $oNewElement, $sSelector Local $oGotElement, $sElementInfos Local $sSaved_StyleOutline, $sSaved_StyleOutline2 ; Loop until the user exits. While IsObj($oIE) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop ; ---> end EndSwitch If ($g_iMouseX <> $iMouseX) Or ($g_iMouseY <> $iMouseY) Then $iMouseX = $g_iMouseX $iMouseY = $g_iMouseY ; $oElement = $oIE.document.elementFromPoint($iMouseX, $iMouseY) ; <-- this way is slower $oNewElement = $JSeval('document.elementFromPoint(' & $iMouseX & ',' & $iMouseY & ');') If $oNewElement <> $oElement Then If IsObj($oElement) Then $oElement.style.outline = $sSaved_StyleOutline $oElement = $oNewElement ; $bSelfie = False ; $iSelf_Timer = TimerInit() $sSaved_StyleOutline = $oElement.style.outline ; save new element's original outline style $sSelector = $_getDomPath($oElement) ; get CSS path If $sSelector <> "" Then ; We could use the $oNewElement, but just to proof that $sSelector is OK ; we get again a reference to the new pointed element using it's $sSelector $oGotElement = $JSeval('document.querySelector("' & $sSelector & '");') ; <-- how to use a selector $oGotElement.style.outline = "1px dashed red" ; mark new pointed element ; https://css-tricks.com/ $sElementInfos = "" & _ "nodeName: " & $oGotElement.nodeName & @CRLF & _ "id: " & $oGotElement.getAttribute('id') & @CRLF & _ "class: " & $oGotElement.getAttribute('class') & @CRLF & _ "type: " & $oGotElement.getAttribute('type') & @CRLF & _ "---------" & @CRLF & _ $sSelector ControlSetText($hGUIMain, "", $hProperties, $sElementInfos) EndIf EndIf EndIf ; $bCopySelector is setted to True by the right-click event on an element, ; see Volatile Func _HTMLElementEvents2_onContextmenu($oEvent) near script bottom If $bCopySelector And ($sSelector <> "") Then ; And (TimerDiff($iSelf_Timer) > $bSelfie_Delay) Then ; $sSaved_StyleOutline2 = $oGotElement.style.outline $oGotElement.style.outline = "5px dotted #ff0066" ; mark copied element ClipPut($sSelector) $sElementInfos &= @CRLF & "selector copied to ClipBoard" ControlSetText($hGUIMain, "", $hProperties, $sElementInfos) Beep(2000, 50) $bCopySelector = False Sleep(250) $oGotElement.style.outline = $sSaved_StyleOutline2 ; ToolTip('') EndIf If _IsPressed("23", $hDLL) Then ; END key pressed If IsObj($oElement) Then $oElement.style.outline = $sSaved_StyleOutline WinActivate($hGUIMain) ; WinSetState($hGUIMain, "", @SW_SHOW) $aWin = WinGetPos($hGUIMain) MouseMove($aWin[0] + $aWin[2] / 2, $aWin[1] + $aWin[3] / 2, 0) EndIf WEnd ; the end ; ------------------------------------------ For $i = 0 To UBound($oEventObjects) - 1 ; Tell IE we don't want to receive events. $oEventObjects[$i] .Stop $oEventObjects[$i] = 0 Next $oIE = 0 ; Remove IE from memory GUIDelete($hGUIMain) ; Remove GUI ; ------------------------------------------ EndFunc ;==>_InspectElements Func _Get_IE() ; Example 5 from the _IEAttach help ; Create an array of object references to all current browser instances ; The first array element will contain the number of instances found Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIEx While 1 $oIEx = _IEAttach("", "instance", $i) If @error = $_IEStatus_NoMatch Then ExitLoop ReDim $aIE[$i + 1] $aIE[$i] = $oIEx $aIE[0] = $i $i += 1 WEnd If $aIE[0] > 0 Then If $aIE[0] = 1 Then Return $aIE[1] ; only one IE is running, return this then ; ; Create a little list box to choose the IE instance from Local $hChoose_IE = GUICreate("IE Instances", 600, 350) Local $Label1 = GUICtrlCreateLabel($aIE[0] & " running Instances of IE browser found, click the one you want to attach to then click on 'ok'", 5, 5, 590, 20) Local $List1 = GUICtrlCreateList("", 5, 30, 590, 300, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) Local $hButton_choosed = GUICtrlCreateButton("OK", 5, 325, 590, 20) For $i = 1 To $aIE[0] GUICtrlSetData($List1, $i & ") " & _IEPropertyGet($aIE[$i], "locationurl")) Next GUISetState(@SW_SHOW) While 1 ; wait for a selection Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hChoose_IE) Return False Case $hButton_choosed $aSelected = _GUICtrlListBox_GetSelItems($List1) If $aSelected[0] Then GUIDelete($hChoose_IE) Return $aIE[$aSelected[1] + 1] Else MsgBox(0, "Info", "Please select an item") EndIf EndSwitch WEnd Else MsgBox(0, 'error', "Sorry" & @CRLF & @CRLF & "no running IE instances found") EndIf EndFunc ;==>_Get_IE ; this function creates a javascript script into the html document ; of the passed $oIE object using the createElement method. Func _JS_Inject($oIE, $sJScript, $bIsUrl = False) ; ; get a reference to the document object Local $objDocument = $oIE.document ; Local $oScript = $objDocument.createElement('script') ; $oScript.type = 'text/javascript' If $bIsUrl Then $oScript.src = $sJScript ; works if $sJScript is a link to a js listing (url) Else ; (https://stackoverflow.com/questions/35213147/difference-between-text-content-vs-inner-text) ; $oScript.innerText = $sJScript $oScript.TextContent = $sJScript ; works if $sJScript contains the listing itself EndIf ; $objDocument.getElementsByTagName('head').item(0).appendChild($oScript) ; $objDocument.getElementsByTagName('head').item(0).removeChild($oScript); ; EndFunc ;==>_JS_Inject ; ------------------------------------------------------------------- ; following function(s) are called by registered $oIE elements events ; ------------------------------------------------------------------- ; ; The function automatically fired by an event ; will receive as parameter an Event Obj. ; This obj has properties related to ; the object that fired the event. ; See following link: ; https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx ; function called by the mousemove event ; we use this to update 2 global variables: Volatile Func _HTMLElementEvents2_onMousemove($oEvent) $g_iMouseX = $oEvent.clientX $g_iMouseY = $oEvent.clientY EndFunc ;==>_HTMLElementEvents2_onMousemove ; function called by the contextmenu event ; we use this to update 1 global variable ; and we also neutralize this event: Volatile Func _HTMLElementEvents2_onContextmenu($oEvent) $oEvent.cancelBubble = True ; event propagation cancelled $oEvent.returnValue = False ; prevent default behaviour $bCopySelector = True ; when True, selector will be copied to clipboard in main loop EndFunc ;==>_HTMLElementEvents2_onContextmenu ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768280%28v%3dvs.85%29 Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel) ;ConsoleWrite("Debug: navigate away cancelled." & @CRLF) ; https://stackoverflow.com/questions/6526876/how-to-cancel-or-dispose-current-navigation-at-webbrowser-element $oIE.stop EndFunc ;==>_IEEvent_BeforeNavigate2 Here is a simple example on how a "selector" can be used in AutoIt.
    suppose we want automate the login to the AutoIt site with our username and password.
    I've already prepared a very simple "template" where are missing some important parts without which the script can't work. Missing parts are the references to the elements of the AutoIt web page that we have to manage by our script.
    well, here is where the tool I have just posted here above comes to our help.
    follow this steps:
    1) in IE open the AutoIt site at the forum page (https://www.autoitscript.com/forum/)
    2) run the above tool (select the IE instance and/or bring it to front if needed)
    3) when the script is "ready", move the mouse over the "Existing user? Sign In" string and right click the mouse button. Doing so the "selector" of that element is copied to the clipboard. Now we can paste it in our AutoLogIt.au3 script as value of the $sSignIn variable.
    4) now click on the "Existing user? Sign In"  to open the "Sig In" session from where we will copy selectors of each of the 2 input box Username and Password, in the same way as we have already done in step 3, and paste those selectors to the $sInputUserId and $sInputPasswd variables respectively.
    5) do the same for the "Sign In" Button and paste it's selector to the $sSignInButn variable
    6) of course also fill the $sMyUserId and $sMyPasswd variables with your data.
    That's It. Run the AutoLogIt script and it should Log you on automatically to the forum.
    AutoLogIt.au3
    #include <ie.au3> $sMyUserId = "" ; <-- your userid here $sMyPasswd = "" ; <-- your password here ; set selectors here $sSignIn = "" ; <-- SigIn element selector here $sInputUserId = "" ; <-- UserId input selector here $sInputPasswd = "" ; <-- Password input selector here $sSignInButn = "" ; <-- Sig In button selector here $oIE = _IECreate("https://www.autoitscript.com/forum/") ; here is how to use the QuerySelector javascript function $hDOM_Element = $oIE.document.QuerySelector($sSignIn) ; get the "sign in" link element ; perform a click action on the above element $hDOM_Element.click() ; or _IEAction($hDOM_Element, "click") as well ; fill the username input $hDOM_Element = $oIE.document.QuerySelector($sInputUserId) $hDOM_Element.value = $sMyUserId ; fill the password input $hDOM_Element = $oIE.document.QuerySelector($sInputPasswd) $hDOM_Element.value = $sMyPasswd ; .... or also using the dot notation directly .... $oIE.document.QuerySelector($sSignInButn).click() Sleep(5000) ; this should logout $sMenu = "body > div:nth-of-type(2) > header > div > ul > li:nth-of-type(6) > a:nth-of-type(2)" $oIE.document.QuerySelector($sMenu).click() $sLogOut = "body > ul > li:nth-of-type(9) > a" $oIE.document.QuerySelector($sLogOut).click()  
  20. Like
    taylansan reacted to badcoder123 in How to run "run"   
    Also
    Run("C:\WINDOWS\system32\rundll32.exe shell32.dll,#61")  
  21. Like
    taylansan reacted to Subz in [Solved] IE drop down list elements   
    Wasn't 100% sure what you were after maybe something like this?
    #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample") _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText") ConsoleWrite("Selected: " & _IEFormElementGetValue($oSelect) & @CRLF) Local $oOptions = _IETagNameGetCollection($oSelect, "Option") For $oOption In $oOptions ConsoleWrite($oOption.InnerText & @CRLF) Next  
  22. Like
    taylansan reacted to Danp2 in [Solved] IE drop down list elements   
    Here's one way --
    #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample") Local $oOptions = _IETagNameGetCollection($oSelect, 'option') For $oOption In $oOptions ConsoleWrite("Option: " & $oOption.value & @CRLF) ConsoleWrite("Option: " & $oOption.innertext & @CRLF) Next  
  23. Like
    taylansan got a reaction from DigDeep in Lable text clickable   
    How about you move that create label before the if check? 
    Func VLC() $filepath = 'C:\Program Files (x86)\VideoLAN\VLC\vlc.exe' $VLC = GUICtrlCreateLabel("VLC", 176, 48, 41, 25) ;create the label before if If FileExists($filepath) Then GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUICtrlSetState($VLC, $GUI_SHOW) Else GUICtrlSetState($VLC, $GUI_HIDE) EndIf EndFunc  
  24. Like
    taylansan reacted to Gianni in [Solved] _IETagNameGetCollection for div - tr - td in a table   
    Hi @taylansan,
    I think you could analyze the html of the page, but maybe the quickest way is the search one by one.
    P.S.
    Some time ago I wrote a function to extract tables from raw html (without the need to make use of a browser), and to test it I also wrote an example script that allows to browse all tables in an html page, If you want to test it below there is the link, you have to use the second script (the example script), from that script you can enter the link of your page. It show all the tables in the page and allows you to visually chose the tables one by one. maybe it can be of use to search your wanted table:
     
  25. Like
    taylansan reacted to Subz in IE.au3 Click button in specifc table.   
    Another method:
    #include <IE.au3> $oIE = _IECreate("https://www.supermakler.pkobp.pl/plus/demo/", 1) $oDivs1 = _IETagNameGetCollection($oIE, "Div") For $oDiv1 In $oDivs1 If StringInStr($oDiv1.id, "x-auto-") Then If StringStripWS($oDiv1.innertext, 8) = "Zlecenia" Then $oDivs2 = _IETagNameGetCollection($oDiv1, "Div") For $oDiv2 In $oDivs2 If StringStripWS($oDiv2.ClassName, 7) = "x-nodrag x-tool-refresh x-tool epm-toolButton x-component" Then _IEAction($oDiv2, "Click") EndIf Next EndIf EndIf Next  
×
×
  • Create New...