Jump to content

Search the Community

Showing results for tags 'best practice'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 3 results

  1. Good morning, everyone, I have had very good luck with using _WD_ElementActionEx 'CLICKANDHOLD'. What would be the best practice with dragging and dropping web elements? I would prefer to not to have to use any dragging and dropping but I haven't figured out a way to change the order the elements are displayed programmatically. I have a list of elements that are drag and drop. These elements in code are using <UL></UL> for the entire list and the actual web elements that are being manipulated are in <LI></LI> tags. These do not look like a bulleted list but that is the code that is being used. I've spoken with the web developer and there isn't any hot keys or keyboard commands that can be used to move these elements. I know where the new and original web element appears and can select them using the _WD_WaitElement and _WD_FindElement combo. I can find the number of items in the list by looking at the code; I haven't started pulling the values out just yet. I am trying to figure out if there is a place to change the listed order. Using the 'CLICKANDHOLD' feature as part of _WD_ElementActionEx does work and I know more or less where I need to drop it the new web element; the problem I am having is scrolling exactly to where I need the new web element dropped. It should be dropped beneath the original web element. What's the best method to output the number of children associated with the <UL></UL>? I am guessing that _WD_ElementActionEx 'CHILDCOUNT' would be it; but I haven't figured out how to get the call to output in a msgbox or in the console. #cs ---------------------------------------------------------------- Name ..........: Please Note!.au3 Description ...: To be used to add new lessons to existing playlists and to update the pre-existing lesson with the Please Note! PowerPoint SciTE 32-bit ..: Version 4.4.6 Author(s) .....: Thomas E. Bennett Date ..........: 20220929 Recommended Reading / Requirements https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-01162021/#comments https://www.autoitscript.com/wiki/WebDriver https://www.autoitscript.com/wiki/WebDriver#Installation https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine wd_core.au3 wd_helper.au3 From wd_core.au3 Global Const $_WD_LOCATOR_ByCSSSelector = "css selector" Global Const $_WD_LOCATOR_ByXPath = "xpath" Global Const $_WD_LOCATOR_ByLinkText = "link text" Global Const $_WD_LOCATOR_ByPartialLinkText = "partial link text" Global Const $_WD_LOCATOR_ByTagName = "tag name" #ce ---------------------------------------------------------------- #include "wd_core.au3" #include "wd_helper.au3" #include <MsgBoxConstants.au3> #include <Excel.au3> #include <AutoItConstants.au3> Local $sDesiredCapabilities, $sSession, $sElement ; Create application object and open an example workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\{PRIVACY}.xlsx") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\{PRIVACY}.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Read data from a single cell on the active sheet of the specified workbook ;Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Data successfully read." & @CRLF & "Value of cell A1: " & $sResult) SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep (15000) Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A16:E16") For $i = 0 To UBound($aResult, 1) - 1 ;ConsoleWrite("========= Start Row =========" & @CRLF) ;ConsoleWrite($aResult[$i][0] & @CRLF) ; Column A -- Course Playlist Number ;ConsoleWrite($aResult[$i][1] & @CRLF) ; Column B -- Course Playlist Title ;ConsoleWrite($aResult[$i][2] & @CRLF) ; Column C -- Original Lesson Title ;ConsoleWrite($aResult[$i][3] & @CRLF) ; Column D -- Updated Lesson Number ;ConsoleWrite($aResult[$i][4] & @CRLF) ; Column E -- Updated Lesson Title ;ConsoleWrite("========= End Row =========" & @CRLF & @CRLF) _WD_Navigate($sSession, "{PRIVACY}" & $aResult[$i][0]) _WD_LoadWait($sSession, 2000) ; Find the Available Lessons search box and enter the appropriate value _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") ; Click the Sign in button _WD_ElementAction($sSession, $sElement, 'value', $aResult[$i][3]) Send("{Enter}") ; Find the correct "Add" hyperlink _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") ; Click the "Add" hyperlink _WD_ElementAction($sSession, $sElement, 'click') ; Number of Child Elements _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") _WD_ElementActionEx($sSession, $sElement, 'CHILDCOUNT') Exit ; Click and Hold the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") _WD_ElementActionEx($sSession, $sElement, 'clickandhold', 0, 0, 0, 10000) ; Hover the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") _WD_ElementActionEx($sSession, $sElement, 'HOVER') Exit Next Exit _WD_DeleteSession($sSession) _WD_Shutdown() Exit Func SetupChrome() ; Google Chrome _WD_Option('Driver', "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe") _WD_Option('Port', 9515) ;_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _ '"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, ' & _ '"prefs": {"credentials_enable_service": false},' & _ '"args": ["start-maximized"] }}}}' EndFunc Console Output >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" /UserParams +>09:22:40 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3 +>09:22:40 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. _WD_Option ==> Success [0] : Parameters: Option=Driver Value=C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe _WD_Option ==> Success [0] : Parameters: Option=Port Value=9515 _WD_IsLatestRelease ==> Success [0] : True _WD_Startup: OS: WIN_10 WIN32_NT 22000 _WD_Startup: AutoIt: 3.3.14.5 _WD_Startup: Webdriver UDF: 0.10.1 (Up to date) _WD_Startup: WinHTTP: 1.6.4.2 _WD_Startup: Driver: C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe (32 Bit) _WD_Startup: Params: _WD_Startup: Port: 9515 _WD_Startup: Command: "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe" _WD_Startup ==> Success [0] __WD_Post ==> Success [0] : HTTP status = 200 _WD_CreateSession ==> Success [0] : 2542b35e47b8f9b2558cd92ad1418811 __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=click Option=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Timeout [7] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div Delay=Default Timeout=Default Options=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=click Option=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ExecuteScript ==> Success [0] _WD_ElementActionEx ==> Success [0] : Parameters: Element=21c01052-8b86-4058-b8f6-d9dfa750f9ee Command=CHILDCOUNT XOffset=Default YOffset=Default Button=Default HoldDelay=Default Modifier=Default +>09:23:20 AutoIt3.exe ended.rc:0 +>09:23:20 AutoIt3Wrapper Finished. >Exit code: 0 Time: 40.88 My thought is once AutoIt knows how many child elements there are; I am hoping that there would be a way to change the sort or priority order that the <LI></LI>'s are shown in. Thank you for your time and efforts on this and as I progress I'll update this topic, Thomas
  2. Hi all, I am working on a GUI program to update Google's Dynamic DNS (API at https://support.google.com/domains/answer/6147083?authuser=1&hl=en if you scroll to bottom). I am not a programmer by any means - just a sysadmin who has picked up on some things along the way. I am sure that there's better ways to do a lot of things in this script; I'm just going with what I know. My challenge right now is that I'd like a better way to store the credentials both in memory as well as in system registry or INI file (not sure which way I want to go for local storage). How should I convert the passwords to a secure string in a manner that can't be easily reversed, yet is still accessible to the script? Is that even an option in AutoIt? Can anybody provide me with links to good reference posts, or coding suggestions for how best to achieve this in the script below? I am using the WinHTTP UDF (https://github.com/dragana-r/autoit-winhttp/releases) to make my API calls. #include<WinHTTP.au3> #include<GUIConstantsEx.au3> #include<EditConstants.au3> #include<iNet.au3> #include<Array.au3> DIM $aDomainList[1][4] $aDomainList[0][0] = 0 $gMainGUI = GUICreate("Overkill's Google DNS Updater",800,800) $gDomainLabel = GUICtrlCreateLabel("FQDN",21,8) $gDomainInput = GUICtrlCreateInput("",60,5,300) $gUserLabel = GUICtrlCreateLabel("Username",5,36) $gUserInput = GUICtrlCreateInput("",60,32,130,Default,BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) $gPasswordLabel = GUICtrlCreateLabel("Password",6,64) $gPassInput = GUICtrlCreateInput("",60,60,130,Default,BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) $gAddButton = GUICtrlCreateButton("ADD DOMAIN",200,31,160,52) $gCurrentIP = GUICtrlCreateLabel("Current IP: " & _CheckIP(),5,780) $gDomainList = GUICtrlCreateListView("Domain | Resolved IP | Update Status",5,120,600,600) GUISetState(@SW_SHOW,$gMainGUI) while 1 $m = GUIGetMsg() IF $M = $GUI_EVENT_CLOSE then Exit IF $M = $gAddButton Then $sAddDomain = GUICtrlRead($gDomainInput) $sAddUser = GUICtrlRead($gUserInput) $sAddPass = GUICtrlRead($gPassInput) $sResolveIP = _DNSCheck($sAddDomain) ;Google wants you to avoid sending updates when there are no changes If StringCompare($sResolveIP,_CheckIP()) = 0 Then $sStatus = "No change, not sending update" Else $sStatus = _DNSUpdate($sAddDomain,$sAddUser,$sAddPass) EndIf ;Check to make sure all fields are completed before continuing IF StringLen($sAddDomain) = 0 OR StringLen($sAddUser) = 0 OR StringLen($sAddPass) = 0 Then MsgBox(0,"","Please complete all fields") Else ; If the fields all have data, then continue ;Check to see if the entry exists in the array already $iSanity = _ArraySearch($aDomainList,$sAddDomain) IF $iSanity = 0 Then _ArrayAdd($aDomainList,$sAddDomain & "|" & $sAddUser & "|" & $sAddPass ) If @error = 0 Then $aDomainList[0][0] += 1 $aDomainList[$aDomainList[0][0]][3] = GUICtrlCreateListViewItem($sAddDomain & "|" & $sResolveIP & "|" & $sStatus,$gDomainList) Else MsgBox(0,"","Error adding input to list") EndIf Else ; If $iSanity <> 0 ; Update existing info in array and listviewitem $aDomainList[$iSanity][0] = $sAddDomain $aDomainList[$iSanity][1] = $sAddUser $aDomainList[$iSanity][2] = $sAddPass GUICtrlSetData($aDomainList[$iSanity][3],$sAddDomain & "|" & $sResolveIP & "|" & $sStatus) EndIf ; If $iSanity = 0 EndIf ; If StringLen... EndIf ; If $m = $gaddbutton WEnd ;---------------------------------------------------------------------------------------- Func _DNSCheck($sFQDN) $sJSON = _INetGetSource("https://dns.google.com/resolve?name=" & $sFQDN & "&cd=1") ConsoleWrite($sJSON & @CRLF) $sIPAddress = StringRegExpReplace($sJSON,'^.*data": "(.*?)".*?$',"\1") Return $sIPAddress EndFunc ;---------------------------------------------------------------------------------------- Func _DNSUpdate($sFQDN,$sUser,$sPass) Local $sGoogleAPIURI = "https://domains.google.com" Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, $sGoogleAPIURI) Local $sHeader = _ 'Authorization: Basic ' & _Base64Encode($sUser & ":" & $sPass) & @CRLF & _ 'Accept: */*' & @CRLF & _ 'User-Agent: AutoITScript/' & @AutoItVersion & @CRLF & _ 'Content-Type: application/x-www-form-urlencoded' Local $aHTTPResponse = _WinHttpSimpleSSLRequest($hConnect, "POST", "/nic/update", Default, "hostname=" & $sFQDN, $sHeader, True, Default, Default, Default, True) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) If IsArray($aHTTPResponse) Then $sHTTPResponse = "Header:" & @CRLF & $aHTTPResponse[0] & @CRLF & "Data:" & @CRLF & $aHTTPResponse[1] & @CRLF & @CRLF & @CRLF Return $aHTTPResponse[1] Else $sHTTPResponse = "NO REPLY" Return "No reply from " & $sGoogleAPIURI EndIf EndFunc ;---------------------------------------------------------------------------------------- Func _Base64Encode($sData) Local $oXml = ObjCreate("Msxml2.DOMDocument") If Not IsObj($oXml) Then SetError(1, 1, 0) EndIf Local $oElement = $oXml.createElement("b64") If Not IsObj($oElement) Then SetError(2, 2, 0) EndIf $oElement.dataType = "bin.base64" $oElement.nodeTypedValue = Binary($sData) Local $sReturn = $oElement.Text If StringLen($sReturn) = 0 Then SetError(3, 3, 0) EndIf Return $sReturn EndFunc ;---------------------------------------------------------------------------------------- Func _CheckIP() Return _INetGetSource("https://domains.google.com/checkip") EndFunc ;----------------------------------------------------------------------------------------
  3. Afternoon! Just a quick one as this has dawned on me recently when creating a little program. When calling an executable I've created like Run(otherapp.exe) from within my executable is there a best practice to ensure things have gone smoothly? So for example, should I monitor the PID to ensure it runs and closes within an acceptable timeframe? Or within my other executable should I do EXITs in a certain way after functions and return codes etc? Could be a silly question but thought I'd ask.
×
×
  • Create New...