Leaderboard
Popular Content
Showing content with the highest reputation on 05/30/2019 in all areas
-
Best way to split an URL in 2 strings
mikell and 2 others reacted to FrancescoDiMuro for a topic
@cetipabo You may use StringRegExp(): #include <Array.au3> #include <StringConstants.au3> Global $strString = "http://www.mywebsite.com/folder1/folder2/index.html", _ $arrResult $arrResult = StringRegExp($strString, 'http://([^/]+)(.*)', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then _ArrayDisplay($arrResult)3 points -
Or you can just use the _WinHttpCrackUrl() function in the winhttp udf by @trancexx and @ProgAndy . #include "MyIncludes\WinHttp\WinHttp.au3" ; <== Change to your location #include <Array.au3> #cs winhttp udf info: https://www.autoitscript.com/forum/topic/84133-winhttp-functions/?tab=comments#comment-602598 _winhttpcrackurl(): Separates a URL into its component parts such as host name and path. Success - Returns array with 8 elements: $array[0] - scheme name $array[1] - internet protocol scheme $array[2] - host name $array[3] - port number $array[4] - user name $array[5] - password $array[6] - URL path $array[7] - extra information #ce ; Cracking URL Global $aUrl = _WinHttpCrackUrl("http://www.mywebsite.com/folder1/folder2/index.html") _ArrayDisplay($aUrl, "_WinHttpCrackUrl()")2 points
-
I don't agree #Include <Array.au3> $strString = "http://www.mywebsite.com/folder1/folder2/index.html" Local $arrResult[2] $aSplit = StringSplit($strString, "/", 1) $arrResult[0] = $aSplit[3] $arrResult[1] = StringReplace($strString, $aSplit[1] & "//" & $aSplit[3], "") _ArrayDisplay($arrResult) yet my heart still belongs to regex2 points
-
As the WebDriver UDF - Help & Support thread has grown too big, I started a new one. The prior thread can be found here.1 point
-
This is the "General Help and Support" thread for the WebDriver UDF. The UDF itself can be downloaded here. So if you have any questions, suggestions or errors please post here.1 point
-
#OnAutoItStartRegister, practical use ???
TheDcoder reacted to argumentum for a topic
There is #OnAutoItStartRegister, and: As the function runs before any of the main script code is executed, the function cannot reference any variables defined in an #include nor any variables defined as Global within the script. All variables within the function are treated as Local. So, what practical use does it have ?1 point -
My solution has advantage of speed as it will be the fastest one as I think. RegExp is slow so if this URL split would be called many times inside some cycle then use my method ...1 point
-
OK. Let's fable about elegance. $url = "http://www.mywebsite.com/folder1/folder2/index.html" MsgBox(64 + 262144, Default, "var1: " & StringTrimLeft(StringLeft($url, StringInStr($url, "/", 1, 3) - 1), 7) & @LF & "var2: " & StringTrimLeft($url, StringInStr($url, "/", 1, 3) - 1), 0)1 point
-
$strString = "http://www.mywebsite.com/folder1/folder2/index.html" execute('assign("domain" , stringleft($strString , StringInStr($strString , "/" , 0 , 3) - 1)) assign("page" , stringright($strString , StringInStr($strString , "/" , 0 , 3) + 1))') msgbox(0, '' , eval("domain") & @LF & eval("page")) edit: suppose it's Exit's. But I was focused on 'elegant'1 point
-
How is that at all helpful to getting yourself some help? Read that line again and imagine you are us trying to figure out WTH you tried or what didn't meet your qualification. You'll find that it's seriously inadequate. The words following that should be edited, what you should have written is, so I'm going to try something else and I'll let you know what I find out. Post your code with exactly what you want and we'll help.1 point
-
WebDriver UDF - Help & Support
Letraindusoir reacted to Danp2 for a topic
It's used when you want to perform an element search starting at a particular element. For example, if you want to get all the rows from a table, first you retrieve the element ID for the table. Then you use this as the starting point for your subsequent find operation, like this -- $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/table") $aRows = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tbody/tr", $sElement, True)1 point -
WebDriver UDF - Help & Support
Danp2 reacted to MONaH-Rasta for a topic
Does anyone can help me to understand how to click on element using right mouse button (contextclick)? I have tried this code (according to what I found in this thread and wd_demo.au3) $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@data-original-title="data 1"]|//a[@title="data 1"]', '', True) If @error = $_WD_ERROR_NoMatch Then ; _TrayTip('Nothing found!') Else For $aElement in $aElements ; _TrayTip('Going to click item...') _WD_ElementAction($sSession, $aElement, 'click') Sleep(1000) Next EndIf $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@data-original-title="data 2"]|//a[@title="data 2"]', '', True) If @error = $_WD_ERROR_NoMatch Then _TrayTip('Nothing found!') Else For $aElement in $aElements _TrayTip('Going to right-click item...') Local $sAction $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"' $sAction &= $aElement & '","' & $_WD_ELEMENT_ID & '":"' & $aElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}' _WD_Action($sSession, "actions", $sAction) sleep(2000) _WD_Action($sSession, "actions") sleep(2000) Next EndIf But right click doesn't "goes" to desired element. I got context menu opened on coordinates x:0 y:0 of document (page). Please, advice. UPD, Now I see my mistake. I was trying to use "$sElement" but my object is "$aElement". All works well now. Sorry for bothering 😎1 point -
Even the example in the help file has errors. MSGBOX () uses a variable that is in an include file and therefore results in an error. MsgBox($MB_SYSTEMMODAL, "", "Function 'Example' is called first.") MsgBox(^ ERROR1 point
-
Control Viewer - AutoIt Window Info Tool
Earthshine reacted to argumentum for a topic
What's New in Version 0.2019.5.30 added: CloneGUI: "msctls_statusbar32" controls fixed: startup /Tray on multi-user setup The files are in the downloads area.1 point -
Best way to split an URL in 2 strings
FrancescoDiMuro reacted to Subz for a topic
Minor tweak to @FrancescoDiMuro code to allow for multiple url variations: #include <Array.au3> #include <StringConstants.au3> Global $arrResult, $arrStrings[][2] = [ _ [1, "https://www.mywebsite.com/folder1/folder2/index.html"], _ [2, "http://www.mywebsite.com/folder1/folder2/index.html"], _ [3, "https://mywebsite.com/folder1/folder2/index.html"], _ [4, "http://mywebsite.com/folder1/folder2/index.html"], _ [5, "www.mywebsite.com/folder1/folder2/index.html"], _ [6, "mywebsite.com/folder1/folder2/index.html"], _ [7, "http://www.mywebsite.com/index.html"], _ [8, "https://mywebsite.com/index.html"] _ ] For $i = 0 To UBound($arrStrings) - 1 $arrResult = StringRegExp($arrStrings[$i][1], '(?:https?:\/\/)?([^/]+)(.*)', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then _ArrayDisplay($arrResult, $arrStrings[$i][0] & ":- " & $arrStrings[$i][1]) Next1 point -
Global $strString = "http://www.mywebsite.com/folder1/folder2/index.html", _ $arrResult[2] $strString = StringReplace($strString, "http://", "", 1, $STR_CASESENSE) $i = StringInStr($strString, '/', $STR_CASESENSE) ; first occurrence If $i > 0 Then $arrResult[0] = StringLeft($strString, $i-1) $arrResult[1] = StringMid($strString, $i) Else $arrResult[0] = $strString $arrResult[1] = "" EndIf _ArrayDisplay($arrResult)1 point
-
or ;~ $url = "http://www.mywebsite.com/folder1/folder2/index.html" $url = "http://www.mywebsite.com/folder1/fol/index.html" ;~ $url = "http://www.mywebsite.com/folder1/index.html" $iPos= StringInStr($url,"/",1,3) $var1 = StringTrimLeft(StringLeft($url,$iPos-1),7) $var2= StringTrimLeft($url,$ipos-1) MsgBox(64+262144, Default, "var1: "&$var1 &@lf&"var2: "&$var2,0)1 point
-
There's probably an unseen character in the copy/paste of the code you're not seeing. Try backsapcing up to the closing parentheses and see if that fixes it.1 point
-
The block of text just above the table you mention explains it all. At least I've tried to make it as "simple" and understandable as possible, but as the inherent working of regex isn't the paradigm most users are used to in their daily programming language(s) it may need some chewing to swallow. Greedy means that a repeated pattern will match the maximum subject input which doesn't cause the rest of the pattern to fail. That may need backtracking. Lazy means that a repeated pattern will match the minimum subject input which doesn't cause the rest of the pattern to fail. That may need backtracking. Possessive means that a repeated pattern will match the maximum subject input, but without ever backtracking backwards inside the "possessed" part. This may cause the rest of the pattern to fail. _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]+)(aba)(.*)", 1), "Greedy") _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]+?)(aba)(.*)", 1), "Lazy") _ArrayDisplay(StringRegExp("AbABAbabbbabaaabbAbAb", "(?i)([ab]++)(aba)(.*)", 1), "Possessive") I used uppercase to help you identify which substring was captured. In the possessive case, the subpattern [ab]++ will match the whole subject, but the rest of the pattern is left with nothing to match, hence failing flat on its nose. In general, the possessive qualifier or its father the atomic grouping (see help) is unavoidable when an unlimited subpattern is enclosed inside another unlimited subpattern and there are instances where no match is possible. In such case the huge number of nested backtrackings required makes the regex extremely slow. Consider this case where we're after an unbounded repeat of "words" (strings of letters) or integers. Subjects which match this pattern will match very fast, but when they don't, the regex will have to try many (really many) nested split points in the subject before failing. Local $s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", $t $t = TimerInit() For $i = 1 To 100 StringRegExp($s, "(\w*|[-\d]*)*[xy]") Next ConsoleWrite("Without possessive qualifier: " & StringFormat("%7.4f\n", TimerDiff($t) / 1000)) $t = TimerInit() For $i = 1 To 100 StringRegExp($s, "(\w*+|[-\d]*)*[xy]") Next ConsoleWrite("With possessive qualifier : " & StringFormat("%7.4f\n", TimerDiff($t) / 1000))1 point
-
As dmob said, easier (and nicer) as a tooltip. Hover over the question mark to activate (In this case button2) Local $Button2 = GUICtrlCreateButton("?", 96, 32, 19, 25) GUICtrlSetTip(-1, "This button will run the IP config command", "This is a ToolTip") -1 is the last GUI control, $Button2 could also be used instead.1 point
-
how to find file location - (Moved)
Earthshine reacted to KaFu for a topic
I tested "Handle" and it seems to work quite good and delivers a lot of info. However it does not show the file opened by notepad++.exe, and the reason for this might be, that there is no open handle, the program reads the data and closes the handle again (e.g. file is deleteable). I could not think of another global method to find open files, I guess it comes down to program specifics, e.g. this seems to work for notepad++.exe. MsgBox(0,"",StringReplace(WinGetTitle("[CLASS:Notepad++]")," - Notepad++",""))1 point -
According to help for GUICtrlCreateMenu https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateMenu.htm here is your code fixed to be working #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <ScrollBarsConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> Local $aWndPos $NetAs = GUICreate("NetAs-Network Assistant", 1096, 497, 182, 135) Local $idFilemenu = GUICtrlCreateMenu("&File") Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu) ;~ Local $idButton = GUICtrlCreateButton("IPConfig", 10, 10, 190, 25) ;~ GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT)) Local $idInput = GUICtrlCreateEdit("", 168, 24, 921, 465) Local $Button1 = GUICtrlCreateButton("IPconfig", 16, 32, 75, 25) Local $Button2 = GUICtrlCreateButton("?", 96, 32, 19, 25) Local $Button3 = GUICtrlCreateButton("Button3", 16, 72, 75, 25) Local $Button4 = GUICtrlCreateButton("?", 96, 72, 19, 25) Local $Button5 = GUICtrlCreateButton("Button5", 16, 112, 75, 25) Local $Button6 = GUICtrlCreateButton("?", 96, 112, 19, 25) Local $Button7 = GUICtrlCreateButton("Button7", 16, 152, 75, 25) Local $Button8 = GUICtrlCreateButton("?", 96, 152, 19, 25) Local $Button9 = GUICtrlCreateButton("Button9", 16, 192, 75, 25) Local $Button10 = GUICtrlCreateButton("?", 96, 192, 19, 25) Local $Button11 = GUICtrlCreateButton("Button11", 16, 232, 75, 25) Local $Button12 = GUICtrlCreateButton("?", 96, 232, 19, 25) Local $Button13 = GUICtrlCreateButton("Button13", 16, 272, 75, 25) Local $Button14 = GUICtrlCreateButton("?", 96, 272, 19, 25) Local $Button15 = GUICtrlCreateButton("Button15", 16, 312, 75, 25) Local $Button16 = GUICtrlCreateButton("?", 96, 312, 19, 25) Local $Button17 = GUICtrlCreateButton("Button17", 16, 352, 75, 25) Local $Button18 = GUICtrlCreateButton("?", 96, 352, 19, 25) Local $Button19 = GUICtrlCreateButton("Button19", 16, 392, 75, 25) Local $Button20 = GUICtrlCreateButton("?", 96, 392, 19, 25) Local $Button21 = GUICtrlCreateButton("Button21", 16, 432, 75, 25) Local $Button22 = GUICtrlCreateButton("?", 96, 432, 19, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idExititem Exit Case $Button1 GUICtrlSetData($idInput, _CmdInfo() & @CRLF) _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET) _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET) EndSwitch WEnd Func _CmdInfo($_sCmdInfo = "ipconfig /all") Local $iPID = Run(@ComSpec & " /c " & $_sCmdInfo, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($iPID) ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead. Local $sOutput = StringReplace(StdoutRead($iPID), @CRLF & @CRLF, @CRLF) Local $sOutErr = StringReplace(StderrRead($iPID), @CRLF & @CRLF, @CRLF) Local $sReult = $sOutput <> "" ? $sOutput : $sOutErr Return $sReult EndFunc1 point
-
$n = _GUICtrlListView_GetItemCount($ListView1) For $i = 0 To $n - 1 $state = _GUICtrlListView_GetItemChecked($ListView1, $i) If $state = True Then ... Next1 point
-
Time ago I wrote a function to extract data from the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that function fits very well to be used with the webBrowser udf. Just save the _HtmlTable2Array.au3 and #include it in your listing. here a simple example of use (I'm using IE here, but of course you can change settings to let the WebDriver use your preferred browser) ; Open a web page with a table, get a reference to the first table ; on the page (index 0) and read its contents into a 2-D array #include <Array.au3> #include 'wd_helper.au3' #include '_HtmlTable2Array.au3' ; <- get it from blow link ; https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ ; === setup WebDriver for IE =============== $_WD_DEBUG = False Global $sDesiredCapabilities Global $sSession _SetupIE() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) ; ========================================== _Example_TableWriteToArray() Func _Example_TableWriteToArray() ; -- open a web page containing a table (ok also if there are more tables) _WD_Navigate($sSession, "https://www.beginnersguidetohtml.com/guides/html/tables/complex-tables") ; get a 'list' of the tables in the page $aTables = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, "table", '', True) ; get the HTML source of the first table (index 0) change index if you need another table $sTable_HTML_source = _WD_ElementAction($sSession, $aTables[0], 'property', 'outerHTML') Local $aMyTable ; ------------------------------------------------------------------------------------ ; the _HtmlTableWriteToArray() function extract the data content from the HTML source ; and save data in a 2d Array. (if second parameter is true it fill cells of the array ; corresponding to the span areas with spanned data (data is spread over the cells) ; ------------------------------------------------------------------------------------ $aMyTable = _HtmlTableWriteToArray($sTable_HTML_source) _ArrayDisplay($aMyTable, "Data without spread") $aMyTable = _HtmlTableWriteToArray($sTable_HTML_source, True) _ArrayDisplay($aMyTable, "Data spreaded") ; ------------------------------------------------------------------------------------ EndFunc ;==>_Example_TableWriteToArray Func _SetupIE() _WD_Option('Driver', 'IEDriverServer.exe') _WD_Option('Port', 5555) _WD_Option('DriverParams', '--log-file=' & @ScriptDir & '\IE.log') $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' EndFunc ;==>_SetupIE1 point
-
You should initially declare $sData as binary and then use _WinHttpReadData() in binary mode ;... $sData = Binary("") ;... $sChunk = _WinHttpReadData($hRequest, 2) ;... ...or use _WinHttpSimpleBinaryConcat() But why not simply: #include "WinHttp.au3" ; Initialize and get session handle $hOpen = _WinHttpOpen() ; Get connection handle $hConnect = _WinHttpConnect($hOpen, "www.mysite.com") ; SimpleSSL-request it... $vReturned = _WinHttpSimpleSSLRequest($hConnect, Default, "/folder/?user=kiki", "http://www.mysite.com/", Default, "Authorization: xxxxxxxxxxxxxxxxxxxx") ; Close handles _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) $hFile = FileOpen(@ScriptDir & "\files.zip", 18) FileWrite($hFile, $vReturned) FileClose($hFile)1 point
-
WebDriver UDF - Help & Support
Letraindusoir reacted to Danp2 for a topic
I believe this can already be done with _WD_FindElement (use $sStartElement with $lMultiple = True) This functionality hasn't made it to the UDF yet. @danylarson did some initial work here and also later in the same thread.1 point -
WebDriver UDF - Help & Support
Letraindusoir reacted to Danp2 for a topic
@Letraindusoir The UDF is designed to implement the functionality of the webdriver specs. I'm not aware of 'stop' being a valid option to submit to the webdriver, so I suspect the webdriver would return an error if you attempted this. As far as your question regarding $sOption, this can contain many different values depending on your usage at the time. It's beyond the scope of this thread / UDF to document all of the various attributes, properties, etc that can be retrieved here.1 point -
WebDriver UDF - Help & Support
cramaboule reacted to Danp2 for a topic
@Letraindusoir If I'm interpreting your question correctly, you are trying to retrieve the URL associated with a hyperlink. If so, then you might want to try something like this -- _WD_ElementAction($sSession, $sElement, 'attribute', 'href')1 point -
AutoIt's variant for a handle does not work as an input to Int(), but does for String(), then it can input to Int(): ; Get handle to active window $hActive = WinGetHandle("") ConsoleWrite("$hActive = " & $hActive & @LF) ; Convert to string $sActive = String($hActive) ConsoleWrite("$sActive = " & $sActive & @LF) ; Convert to integer $iActive = Int($sActive) ConsoleWrite("$iActive = " & $iActive & @LF) ; Convert back to handle $hActive = HWnd($iActive) ConsoleWrite("$hActive = " & $hActive & @LF) ; Test the handle $sTitle = WinGetTitle($hActive) ConsoleWrite("$sTitle = " & $sTitle & @LF)1 point