
bailey1274
Active Members-
Posts
31 -
Joined
-
Last visited
Everything posted by bailey1274
-
IE proxy usage with login and password.
bailey1274 replied to ogloed's topic in AutoIt General Help and Support
I know this topic is crazy old but if anyone else stumbles across this there is a solution. Windows credentials manager. Adding your proxies IP along with username and password as a Generic Windows credential will get picked up by all IE instances and will authenticate for you. Also you can modify these credentials programmatically using the command line, "cmdkey", and to change proxies programmatically, use registry edits on your internet options.- 8 replies
-
- ie
- internet explorer
-
(and 2 more)
Tagged with:
-
Exactly, personally I just wasn't a fan of the syntax the functional approach uses. It feels a bit clunky to me. I think it just comes down to my preference of objects over functional programming. Don't really have any expectations other than readability (and possibly adding things like that map method). If I want to reference a dictionary value inside of another function, calling a function to access it as a parameter just feels off to me. (I think my affinity for python I think pulls me to match syntax when I can) I unfortunately can't use the beta in my environment or maps would be great.
-
I use Python and Autoit about half the time and always wished that AutoIt had an associative array like the dictionary data type. I've found some examples but many were functional based and seemed disconnected to me. I have been using the AutoItObject.au3 by monoceres, trancexx, Kip, and Prog@ndy (big shoutout there, this thing is amazing) and tried to take a stab at wrapping up a dictionary in an object. Would love any feedback or ideas to make it better, it is pretty rough at this point and could use more work but the idea is there. #include "AutoitObject.au3" #include "Array.au3" Local $my_dict = Dict( _ 'dog', ' woof ' _ ,'cat', ' meow' _ ,'owl', ' hoot ' _ ) msgbox(0, '', $my_dict.to_string()) $my_dict.map(StringStripWS, 3) msgbox(0, '', $my_dict.to_string()) $my_dict.map(StringReplace, 'meow', 'purr') msgbox(0, '', $my_dict.to_string()) ; #FUNCTION# ==================================================================================================================== ; Name ..........: Dict ; Description ...: Creates a wrapper object for a dictionary ; Parameters ....: $kX-$vX - Key-Value pairs ; Return values .: Success - Object containing a dictionary ; Failure - Null ; @extended - N/A ; =============================================================================================================================== Func Dict( _ $k1=Default, $v1=Default _ ,$k2=Default, $v2=Default _ ,$k3=Default, $v3=Default _ ,$k4=Default, $v4=Default _ ,$k5=Default, $v5=Default _ ,$k6=Default, $v6=Default _ ,$k7=Default, $v7=Default _ ,$k8=Default, $v8=Default _ ,$k9=Default, $v9=Default _ ,$k10=Default, $v10=Default _ ,$k11=Default, $v11=Default _ ,$k12=Default, $v12=Default _ ) ; Initialize AutoItObject _AutoItObject_StartUp() Local $oClassObject = _AutoItObject_Class() $oClassObject.Create() ; -- Create Length Prop -- ; Local $Props = ['len'] ; -- Create our Dictionary -- ; Local $oDict = ObjCreate('Scripting.Dictionary') ; -- Add any init key-value pairs -- ; Local $iLen = 0 If $k1 Then $iLen += 1 $oDict.add($k1,$v1) EndIf If $k2 Then $iLen += 1 $oDict.add($k2,$v2) EndIf If $k3 Then $iLen += 1 $oDict.add($k3,$v3) EndIf If $k4 Then $iLen += 1 $oDict.add($k4,$v4) EndIf If $k5 Then $iLen += 1 $oDict.add($k5,$v5) EndIf If $k6 Then $iLen += 1 $oDict.add($k6,$v6) EndIf If $k7 Then $iLen += 1 $oDict.add($k7,$v7) EndIf If $k8 Then $iLen += 1 $oDict.add($k8,$v8) EndIf If $k9 Then $iLen += 1 $oDict.add($k9,$v9) EndIf If $k10 Then $iLen += 1 $oDict.add($k10,$v10) EndIf If $k11 Then $iLen += 1 $oDict.add($k11,$v11) EndIf If $k12 Then $iLen += 1 $oDict.add($k12,$v12) EndIf ; -- Add the length and dictionary to be accessed via methods -- ; $oClassObject.AddProperty('len', $ELSCOPE_PUBLIC, $iLen) ; Create Length Property binded to object $oClassObject.AddProperty('dict', $ELSCOPE_PUBLIC, $oDict) ; Create actual Dictionary as property to access in methods ; -- All methods (all rely on the dictionary prop) -- ; $oClassObject.AddMethod("get", "get") $oClassObject.AddMethod("set", "set") $oClassObject.AddMethod("keys", "keys") $oClassObject.AddMethod("values", "values") $oClassObject.AddMethod("exists", "exists") $oClassObject.AddMethod("to_string", "to_string") $oClassObject.AddMethod("clear", "clear") $oClassObject.AddMethod("remove", "remove") $oClassObject.AddMethod("map", "map") ; -- Add destructor -- ; $oClassObject.AddDestructor("Dict_Destructor") Return $oClassObject.Object EndFunc ; -- Destorys the Dict upon deletion of object -- ; Func Dict_Destructor($oSelf) ConsoleWrite("Destorying Dict") $oSelf.dict.RemoveAll EndFunc ; -- Sets the value for a given key -- ; Func set($oSelf, $sKey, $sValue) If $oSelf.dict.Exists($sKey) Then $oSelf.remove($sKey) $oSelf.dict.add($sKey, $sValue) Else $oSelf.len += 1 $oSelf.dict.add($sKey, $sValue) EndIf EndFunc ; -- Gets the value for a key -- ; Func get($oSelf, $sKey) If $oSelf.dict.Exists($sKey) Then Return $oSelf.dict.Item($sKey) Else Return "KEY_ERR" EndIf EndFunc ; -- Removes the Key-Value pair by key -- ; Func remove($oSelf, $sKey) If $oSelf.dict.Exists($sKey) Then $oSelf.dict.Remove($sKey) Return Else Return "KEY_ERR" EndIf EndFunc ; -- Returns an array of keys -- ; Func keys($oSelf) Local $aKeys[0] For $item in $oSelf.dict.Keys _ArrayAdd($aKeys, $item) Next Return $aKeys EndFunc ; -- Returns the Array of Values -- ; Func values($oSelf) Local $aVals[0] For $item in $oSelf.dict.Items _ArrayAdd($aVals, $item) Next Return $aVals EndFunc ; -- Returns Bool if keys exists or not -- ; Func exists($oSelf, $sKey) If $oSelf.dict.Exists($sKey) Then Return True EndIf Return False EndFunc ; -- Returns a json notation string -- ; Func to_string($oSelf) Local $aKeys = $oSelf.keys Local $aVals = $oSelf.values Local $str = "{"&@CRLF For $i=0 to UBound($oSelf.keys)-1 $str &= @TAB &'"'& $aKeys[$i] &'"'& ', "'& $aVals[$i] &'"'&@CRLF Next $str &= "}" Return $str EndFunc ; -- Clears the entire dict -- ; Func clear($oSelf) $oSelf.len = 0 $oSelf.dict.RemoveAll() EndFunc ; -- Maps given function to the values -- ; Func map($oSelf, $oFunc, $param1=Default, $param2=Default) If $param2 and $param1 Then For $key in $oSelf.keys $oSelf.set($key, $oFunc($oSelf.get($key), $param1, $param2)) Next ElseIf $param1 Then For $key in $oSelf.keys $oSelf.set($key, $oFunc($oSelf.get($key), $param1)) Next EndIf EndFunc
-
Thanks guys, this may be the closest to get what I'm trying to achieve local $test = "a" local $my_func = "DoSomething('123')" $test = "b" execute($my_func) func DoSomething($sText) ConsoleWrite('Foo Bar sText = '& $sText & $test & @CRLF) return 0 endfunc My goal is to have one variable that contains some function call with a certain parameter and be able to call that variable without giving params every time BUT ALSO be able to change that param at various sections of the script. I think this is the closest that I'll get to this sort of functionality in AutoIt. local $ERROR local $my_obj1 = ObjCreate(...) $ERROR = "Error($my_obj1)" do_something($my_obj1) If @error Then execute($ERROR) ; More Code local $my_obj2 = ObjCreate(...) $ERROR = "Error($my_obj2)" do_something($my_obj2) If @error Then execute($ERROR) func Error(ByRef $this_obj) ; Clean things up, log & destroy this obj endfunc func do_something(ByRef $this_obj) ; some function call that uses this_obj If @error Then Return SetError(1) endfunc
-
So I know this is possible local $my_func = DoSomething $my_func() func DoSomething() ConsoleWrite('Foo Bar') endfunc But to me, this doesn't seem to add much usefulness. Maybe a couple edge cases to make things more readable? Although my question is if there is any way the following would be achievable? local $my_func = DoSomething('1') ; $my_func is now 0 but I would like to be able to call the varibale as a reference to the parameter passed in at the time of assignment $my_func() ; -> wont work func DoSomething($sText) ConsoleWrite('Foo Bar sText = '&sText) return 0 endfunc
-
The goal is to have a callable function that can be used and updates variables, not arrays of values. I think with the limitations of autoit, it may not be possible. It could be achieved using all global variables but that's something I don't want to do. The only way to have a callable function that updates the original local variables in the function would to be using byRefs but also having an arbitrary number of params. This can't be done since optional byRefs aren't supported which is why I put the values into an array with the corresponding names next to them to use after the array has been cleaned and then assign back to original vars. I was just hoping someone had a not so intuitive way that I'm not seeing how to do it.
-
#include <Array.au3> LocalFunction() Func LocalFunction() ; Goal is to have one function act on all of these Local $Var1 = ' Trim Me 1 ' Local $Var2 = ' Trim Me 2 ' Local $Var3 = ' Trim Me 3 ' ; Function/Params of what you want to apply to a list/set of vars Local $FuncArr[2] = [StringStripWS, 3] ; Var names next to vars. If we could byRef these somehow to avoid the For loop after the Apply then it would be great Local $VarArr[6] = [$Var1, 'Var1', $Var2, 'Var2', $Var3, 'Var3'] ; Apply our function to our list of variables Apply($FuncArr, $VarArr) ; Reassign our updated array back to our original variables Local $val For $var=0 to UBound($VarArr)-1 If Mod($var, 2) = 0 Then ; Grab the updated values $Val = $VarArr[$var] ContinueLoop EndIf Assign($VarArr[$var], $Val) ; Assign value to correct name Next MsgBox(0,'Var1', '['&$Var1&']') MsgBox(0,'Var2', '['&$Var2&']') MsgBox(0,'Var3', '['&$Var3&']') EndFunc Func Apply($aFunc, byRef $arr) For $var=0 to UBound($arr)-1 If Mod($var, 2) <> 0 Then ContinueLoop ; Avoid the variable name strings $arr[$var] = Call($aFunc[0], $arr[$var], $aFunc[1]) Next EndFunc So heres the code, it gets close to what I want although does anyone have any ideas how to avoid the For Loop after the apply function? If there is a way to create an array with references back to the variables themselves instead of just passing the values, this wouldn't be so ugly. The goal is to just be able to call one function on a large set of variables without having to reassign them individually. This does work but, imo, its pretty ugly and would only be worth it for a very large set of variables since the implementation of this pattern is at minimum like 10 lines.
-
WebDriver UDF - Help & Support (II)
bailey1274 replied to Danp2's topic in AutoIt General Help and Support
So maybe someone here could help me figure out how to disable javascript when using Chrome. I've tried this to no avail {"capabilities": {"javascriptEnabled":false, "alwaysMatch": {"unhandledPromptBehavior": "ignore", "goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, "args": ["start-maximized", "headless"]}}}} There is tons of help using other languages about web driver but with AutoIt, it seems rather sparse with info about how to go upon controlling webdriver through http requests. Any ideas? -
Okay so my background is mainly with Java, Python and Autoit and here is my view. Depending on the task you are trying to accomplish is where the answer to this question lies. For more simple (smaller) standalone programs where you are not interacting with anything outside of what you are working on, maybe like a Gui or something that does one or two tasks, then I'd say AutoIt would be a good bet. It has all the building blocks one would need to get the logic down and look somewhat presentable. However if that Gui is to grow into an entire application, then I'd lean more towards something like Python that is an OOP language. The separation of concern that OOP languages offer, imo, will lead to a much more maintainable and supportable code that won't be such a pain to scale into something bigger. Although I think the biggest reason to use Python or Java (or OOP) over Autoit is simply the frameworks and libraries available to you with these other languages. While AutoIt is a great language, its not as widespread as some other ones are and hence sometimes does not offer exactly what you are looking for. For example one of the use cases I've used AutoIt and Python for is Web-scraping. Let's say I was trying to make a bot to scrape a list of websites as quickly as possible. While I could use the IE library, I would need to wait for the creation of the IE object, then navigate thru their site by clicks or something of the like until I was able to visit every page on the site and do a _IEBodyReadHtml or pull all the Dom objects I was after. Without a doubt this will work. But say I was doing this for 5,000 websites.. this would take a long time. I could optimize the time by simply making HTTP requests to get the data instead and not wait for all that IE stuff. But with AutoIt, I would then need to parse the HTML or JSON myself using regular expressions or something else I would need to write. This would be a lot of work to either generalize this task into my own UDF to use or to make 5000 different sets of parsing code, one for each website. HOWEVER If I was aware that python has two very known and very used modules called the Requests library and the BeautifulSoup library, then all of that work is already done for me. I do not have to reinvent the wheel by creating all this parsing logic and with the use of these libraries can reduce the amount of work I'd have to do tenfold. So smaller stuff, AutoIt but if you want something scalable, an OOP Language. But that just my opinion...
-
So I am looping through a large Json array and then placing extracted values inside of an autoit array to use later. I can successfully get through Json Arrays around the size of 20,000 objects without a problem and the array is displayed fine and script continues. However when the Json Array is larger, around 42,000 objects, the script simply crashes about 50% of the way through adding the values to the array. I initially had a 4 column array and placing values in columns 1-4 and that crashed with no errors displayed and no COM errors thrown, and yes, I have a COM error handler in place. I then switched it be a one column array and just delimit the values with a tilde, which seemed to help as it got further into the array before crashing, but still did. I am kind of at a loss since there is literally zero logging to go off of here and I am not sure how to even track the problem down. For $i = 0 to $numOfResults-1 While 1 $aTag = Json_Get($oJson,"["&$i&"].licenseNumber") $href = 'https://site.com/'&StringRegExpReplace($aTag, ".*?href='(.*?)'.*",'$1') $Number = StringRegExpReplace($aTag, ".*?\>(.*?)\<.*",'$1') $First = Json_Get($oJson,"["&$i&"].firstName") $Last = Json_Get($oJson,"["&$i&"].lastName") $Type = Json_Get($oJson,"["&$i&"].recordAlias") ExitLoop WEnd If @error then LogErr("ERROR: Parsing Names, Num, Href, and Type from JSON; Err = "&@Error) Return "ERROR" EndIf _ArrayAdd($HrefArray, $href&"~"&$licNum&"~"&$First&"~"&$Last) If @error Then LogErr("ERROR: Could not add Details to Array; Err = "&@Error) Return "ERROR" Else LogErr("SUCCESS: Added to Array ["&$href&"~"&$licNum&"~"&$First&"~"&$Last&"]") EndIf Next _ArrayDisplay($HrefArray) Has anyone seen this behavior before? The array is not over the maximum autoit array size and nothing else seems to be wrong. This is my last hope before adding a dumb amount of logging to both the Array.au3 and Json.au3 to see why this is actually occurring.
-
So I am coming across an issue that I can't seem to solve. It may not be specific to AutoIt but thats what I am using right now. I am simply trying to make post requests using a WinHttpRequest object. Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("POST", $sURL, False) If (@error) Then Return SetError(1, 0, 0) If $JSON = False Then $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") Else $oHTTP.SetRequestHeader("Content-Type", "application/json") EndIf $oHTTP.Send($sData) If (@error) Then Return SetError(2, 0, 0) If ($oHTTP.Status <> 200) Then Return SetError(3, 0, 0) Return SetError(0, 0,$oHTTP.ResponseText) This code executes fine on Windows 10 and brings back the JSON I'm after although on Windows 7 it fails every time on the Send() function. When using a COM error handler I get an error of "The connection with the server was terminated abnormally". There are no proxies or anything acting on the connection that I know of. The one thing I tried to no avail was enabling TLS 1.2 and 1.1 on the OS as opposed to the windows 7 default SSL but still the same issue. Anyone have any idea whats going on here between windows 10 and 7 thats causing the issue?
-
SciTE line margin color?
bailey1274 replied to bailey1274's topic in AutoIt General Help and Support
@Jos Thank you, this worked perfect. Is there any documentation or a list on what numbers mean what? I searched for a decent while yesterday and couldn't find anything on it. -
Is there any way of changing the color of the SciTE line margins? I was able to change the size of it via the SciTEUser.properties file with "line.margin.width" but no luck finding anything about the background or text color. I tried a few things like "line.margin.fore", "line.margin.back" but to no avail. Is there any way to do this?
-
Help with if condition is not met then restart loop
bailey1274 replied to ags911's topic in AutoIt General Help and Support
One way to accomplish this would be recursion. Here is a small sample about how to go upon it. But be careful as you can easily create infinite loops if you don't scope variables correctly. Also using the code input tool here on the forums always helps readability. -
I have a window that I want to make smaller. That is not to just resize it. as that causes scroll bars to pop up, but actually make everything smaller. Its a virtual machine window that I want to drop in the corner of my screen without it taking up too much space because as it sits now its about half the size. When I resize it, the scroll bars pop up and I won't be able to see the full screen which is not what I'm hoping to do. I would guess this has to do something with resolution but I am not too sure and about how or if its possible to go upon it. Any help would be very appreciated.
-
I ended up figuring out what it was after some trial and error. Turns out the readystate for the window was not complete. I'm guessing since the body of the document or the document itself was not available it was causing the error to occur at the Line where it checks the body for the text input criteria. I had to pull the function out locally and add a small check to make sure the $oWindow.readystate was complete before proceeding and it now works. If anyone else happens to stumble on this error then something like this should work. Case "html" While $oWindow.readystate <> 'complete' and $oWindow.readystate <> 4 ConsoleWrite('readystate sleep') Sleep(2000) WEnd If StringInStr($oWindow.document.body.innerHTML, $sString) > 0 Then If $iInstance = $iTmp Then Return SetError($_IESTATUS_Success, 0, $oWindow) Else $iTmp += 1 EndIf EndIf
-
@@ Trace(501) : If $bIsBrowser Then 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:>Error code: 0 @@ Trace(503) : Switch $sMode 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:>Error code: 0 @@ Trace(581) : If StringInStr($oWindow.document.body.innerText, $sString) > 0 Then 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:--> COM Error Encountered in Script1 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrScriptline = 581 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrNumberHex = 00000004 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrNumber = 4 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrWinDescr = NULL Pointer assignment 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrDescr = 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrSource = 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrHelpFile = 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrHelpContext= 2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrLastDllErr = 0 It's consitently on the 15th iteration of loading the new page.. anyone have ideas on why this could be occuring??
-
So my problem here is that I cannot think of any approach other than just an overkill of sleep to solve this. I have an onclick event that opens a new tab and I want to do some stuff on the new page being opened, no href or url is given. I'm using IEAttach after a sleep of 10 seconds which for the most part works but occasionally it does not because the page stays in a loading state for longer than that and since the URL is the same as the page before I have to use the 'text' option in order to successfully attach it. I can't use IELoadwait due to not having used IEAttach yet so I am not sure how to handle this. Is there any way to check the state of the browsers current page and proceed once we know the new page has actually been loaded?
-
Ternary Operator Syntax - throwing errors
bailey1274 replied to bailey1274's topic in AutoIt General Help and Support
This does seem like a good example why its not just a replacement for any if-then. And imo creating a new variable sort of defeats the purpose of being a shorthand as you're doing something extra to make it work. I'm too lazy for all that. My takeaway, just use ternarys for returning values and not executing things. -
Ternary Operator Syntax - throwing errors
bailey1274 replied to bailey1274's topic in AutoIt General Help and Support
Ah so on the first iteration, returning Null works as I would hope because that causes nothing to happen. However on $row=1, it returns a ContinueLoop but does not actually execute it and this somehow causes an error. I get it a little more now, but still a little hazy on why I get that specific error message. Although I guess either way, I'm using it in the wrong context. -
Ternary Operator Syntax - throwing errors
bailey1274 replied to bailey1274's topic in AutoIt General Help and Support
So ternarys will only work in return statements and not just a simple command? Why does it work in a message box like in the example? And that adds to the confusion on why the first iteration works and the following ones do not. -
Ternary Operator Syntax - throwing errors
bailey1274 replied to bailey1274's topic in AutoIt General Help and Support
Well yeah, this works like I mentioned in the post but I'm more just curious why its not working. -
Can someone please explain why this expression keeps throwing errors? I've tried so many different combinations of parentheses around each part/the entire expression. For $row = 0 to UBound($aTableData,1)-1 (Mod($row,7)=0) ? (Null) : (ContinueLoop) This gives "Error: Missing right bracket ')' in expression" Sometimes with other parentheses combinations I just get 'Error in expression' which I'm assuming is just a syntax error but at this point I'm not sure. The $aTableData is an array of 100+ rows and the oddest part is that when $row = 0, the expression evaluates as expected but when it moves on, I keep getting these errors. It works fine with a plain If-Then statement so I'm assuming this has to be syntax.