Jump to content

Arlen

Active Members
  • Posts

    50
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Arlen's Achievements

Wayfarer

Wayfarer (2/7)

2

Reputation

  1. Thanks for the recommendation but the code is just an example, I need to loop through all lines to match the correct string using regex
  2. Hello I'm trying to use _FileWriteToLine to update a new line into a txt file, but I can't get it to write on the correct line, this is what I have tried: Text file content is: one two three four Attempt #1 #include <File.au3> $FileLine = FileReadToArray("testy.txt") $Lines = @extended If IsArray($FileLine) Then For $i = 0 To $Lines-1 If StringInStr($FileLine[$i], "three") Then _FileWriteToLine("testy.txt", $i, "three is 3", True) ExitLoop EndIf Next EndIf Attempt #2 #include <File.au3> $FileLine = FileReadToArray("testy.txt") $Lines = @extended If IsArray($FileLine) Then For $i = 1 To $Lines Step 1 If StringInStr($FileLine[$i], "three") Then _FileWriteToLine("testy.txt", $i, "three is 3", True) ExitLoop EndIf Next EndIf I always get this result: one three is 3 three four Instead of: one two three is 3 four
  3. How do I know I got multiple results from "_WD_FindElement", does it return an array (tried)? $sList = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='listing-content']") _WD_ElementAction($sSession, $sList, 'text') In this example I know there are multiple classname "listing-content" but only see text from the first one.
  4. _WD_ExecuteScript($sSession, "$(#CurrencyCalc).removeClass('hidden');") What am I doing wrong?
  5. Well basically if I'm able to run a jQuery, I can unhide an element. Is it possible with WD?
  6. I would like to edit a classname, so I can remove the word "hidden" and then search the text. By default I have to hover mouse to get the text to show up.
  7. Chrome won't open. Updated chromedriver.exe I get this msg on Console: "Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code." I have AV BTW.
  8. No, it was the UDF. Before (V0.1.0.18😞 ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_ElementAction ; Description ...: Perform action on desginated element ; Syntax ........: _WD_ElementAction($sSession, $sElement, $sCommand[, $sOption = '']) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $sElement - Element ID from _WDFindElement ; $sCommand - Action to be performed ; $sOption - [optional] a string value. Default is ''. ; Return values .: Success - Requested data returned by web driver ; Failure - "" ; @ERROR - $_WD_ERROR_Success ; - $_WD_ERROR_NoMatch ; - $_WD_ERROR_Exception ; - $_WD_ERROR_InvalidDataType ; @EXTENDED - WinHTTP status code ; Author ........: Dan Pollak ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: https://www.w3.org/TR/webdriver#element-state ; https://www.w3.org/TR/webdriver#element-interaction ; Example .......: No ; =============================================================================================================================== Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption = '') Local Const $sFuncName = "_WD_ElementAction" Local $sResponse, $sResult = '', $iErr, $oJson, $sErr $sCommand = StringLower($sCommand) Switch $sCommand Case 'name', 'rect', 'text', 'selected', 'enabled', 'displayed', 'screenshot' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand) $iErr = @error Case 'active' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sCommand) $iErr = @error Case 'attribute', 'property', 'css' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand & "/" & $sOption) $iErr = @error Case 'clear', 'click' $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand, '{"id":"' & $sElement & '"}') $iErr = @error Case 'value' $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand, '{"id":"' & $sElement & '", "text":"' & $sOption & '"}') $iErr = @error Case Else Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Name|Rect|Text|Selected|Enabled|Displayed|Active|Attribute|Property|CSS|Clear|Click|Value|Screenshot) $sCommand=>" & $sCommand), 0, "") EndSwitch If $iErr = $_WD_ERROR_Success Then If $_WD_HTTPRESULT = $HTTP_STATUS_OK Then Switch $sCommand Case 'clear', 'click', 'value' $sResult = $sResponse Case Else $oJson = Json_Decode($sResponse) $sResult = Json_Get($oJson, "[value]") EndSwitch ElseIf $_WD_HTTPRESULT = $HTTP_STATUS_NOT_FOUND Then $oJson = Json_Decode($sResponse) $sErr = Json_Get($oJson, "[value][error]") $iErr = ($sErr == $WD_Element_Stale) ? $_WD_ERROR_NoMatch : $_WD_ERROR_Exception Else $iErr = $_WD_ERROR_Exception EndIf EndIf If $_WD_DEBUG = $_WD_DEBUG_Info Then ConsoleWrite($sFuncName & ': ' & StringLeft($sResponse,100) & "..." & @CRLF) EndIf If $iErr Then Return SetError(__WD_Error($sFuncName, $iErr, $sResponse), $_WD_HTTPRESULT, "") EndIf Return SetError($_WD_ERROR_Success, $_WD_HTTPRESULT, $sResult) EndFunc ;==>_WD_ElementAction After(New V0.1.0.18): the change occurred from V0.1.0.15 to V0.1.0.16 ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WD_ElementAction ; Description ...: Perform action on desginated element ; Syntax ........: _WD_ElementAction($sSession, $sElement, $sCommand[, $sOption = '']) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $sElement - Element ID from _WDFindElement ; $sCommand - Action to be performed ; $sOption - [optional] a string value. Default is ''. ; Return values .: Success - Requested data returned by web driver ; Failure - "" ; @ERROR - $_WD_ERROR_Success ; - $_WD_ERROR_NoMatch ; - $_WD_ERROR_Exception ; - $_WD_ERROR_InvalidDataType ; @EXTENDED - WinHTTP status code ; Author ........: Dan Pollak ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: https://www.w3.org/TR/webdriver#element-state ; https://www.w3.org/TR/webdriver#element-interaction ; Example .......: No ; =============================================================================================================================== Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption = '') Local Const $sFuncName = "_WD_ElementAction" Local $sResponse, $sResult = '', $iErr, $oJson, $sErr $sCommand = StringLower($sCommand) Switch $sCommand Case 'name', 'rect', 'text', 'selected', 'enabled', 'displayed', 'screenshot' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand) $iErr = @error Case 'active' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sCommand) $iErr = @error Case 'attribute', 'property', 'css' $sResponse = __WD_Get($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand & "/" & $sOption) $iErr = @error Case 'clear', 'click' $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand, '{"id":"' & $sElement & '"}') $iErr = @error Case 'value' Local $sSplitValue = "[" & StringTrimRight(StringRegExpReplace($sOption, '\\u[[:alnum:]]{4}|.', '"$0",'), 1) & "]" $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand, '{"id":"' & $sElement & '", "text":"' & $sOption & '", "value":' & $sSplitValue & '}') $iErr = @error If $iErr = $_WD_ERROR_Success Then $sResult = $sResponse EndIf Case Else Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Name|Rect|Text|Selected|Enabled|Displayed|Active|Attribute|Property|CSS|Clear|Click|Value|Screenshot) $sCommand=>" & $sCommand), 0, "") EndSwitch If $iErr = $_WD_ERROR_Success Then If $_WD_HTTPRESULT = $HTTP_STATUS_OK Then Switch $sCommand Case 'clear', 'click', 'value' $sResult = $sResponse Case Else $oJson = Json_Decode($sResponse) $sResult = Json_Get($oJson, "[value]") EndSwitch ElseIf $_WD_HTTPRESULT = $HTTP_STATUS_NOT_FOUND Then $oJson = Json_Decode($sResponse) $sErr = Json_Get($oJson, "[value][error]") $iErr = ($sErr == $WD_Element_Stale) ? $_WD_ERROR_NoMatch : $_WD_ERROR_Exception Else $iErr = $_WD_ERROR_Exception EndIf EndIf If $_WD_DEBUG = $_WD_DEBUG_Info Then ConsoleWrite($sFuncName & ': ' & StringLeft($sResponse,100) & "..." & @CRLF) EndIf If $iErr Then Return SetError(__WD_Error($sFuncName, $iErr, $sResponse), $_WD_HTTPRESULT, "") EndIf Return SetError($_WD_ERROR_Success, $_WD_HTTPRESULT, $sResult) EndFunc ;==>_WD_ElementAction Difference is on the case 'value' section.
  9. I did some tweaks to make it work for me on version 0.1.0.18.1
  10. You can't test it unless you have my router to visit the IP or..?, here is the Logs. (Yes it did solve my firefox issue earlier) Also it says " _WDStartup: WD.au3: 0.1.0.17 " but it's not true I downloaded the latest with github 0.1.0.18 You can test this: #RequireAdmin #include <wd_core.au3> #include <wd_helper.au3> Global $sDesiredCapabilities = "{}", $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.google.com/") MsgBox(0,"","stop") _ChromeSetInputValueByClass($sSession,'gLFyf gsfi','abc') Func _ChromeSetInputValueByClass($sSession,$Class,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@Class='"&$Class&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] }}}}' EndFunc ;==>SetupChrome
  11. This is not working for me: _ChromeSetInputValueById($sSession,'txt_Username','usertest') _ChromeSetInputValueById($sSession,'txt_Password','somepw') Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc <input style="font-size:12px;font-family:Tahoma,Arial;" id="txt_Password" class="input_login" name="txt_Password" type="password" maxlength="127"> <input style="font-size:12px;font-family:Tahoma,Arial;" id="txt_Username" class="input_login" name="txt_Username" type="text" maxlength="31"> EDIT: I notice that with WD Version 0.1.0.15 it works but with v0.1.0.18 it doesn't work.
  12. Can't navigate on Firefox, it will open and then console will relaunch and Firefox again. Also is it possible to run any browser hidden like IE COM has visible option.
  13. How can I click Chrome alert message? Trying to make my router restart with Web Driver UDF, but can't figure out how to click the message: "Unsaved data will be lost. Are you sure you want to restart the device?" (Yes or No) I have tried, controlclick, controlsend and send (While window was active). Any other solution? EDIT: Found solution, didn't notice WD had a function called " _WD_Alert " which helped me remove the alert.
×
×
  • Create New...