Danyfirex Posted July 6, 2018 Share Posted July 6, 2018 @slvtn666 It seems to be an Encoding issue try with the ANSI version of the string. I think is this: local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'Почта')]") Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
slvtn666 Posted July 6, 2018 Share Posted July 6, 2018 1 hour ago, Danyfirex said: @slvtn666 It seems to be an Encoding issue try with the ANSI version of the string. I think is this: local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'Почта')]") Saludos Yep, trouble with encoding. When i run script _WD_Navigate($sSession, "https://www.google.com/?hl=ru") $postElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[text()='Почта']") _WD_ElementAction($sSession, $postElement, 'click') then console outputs: __WD_Post: URL=HTTP://127.0.0.1:9515/session/17a3ab0c0e832096cced6f54f25ffdb5/element; $sData={"using":"xpath","value":"//*[text()='Почта']"} __WD_Post: StatusCode=400; ResponseText=missing command parameters _WD_FindElement: missing command parameters But when i change interface language and search for element contains "Gmail" it works fine, _WD_Navigate($sSession, "https://www.google.com/?hl=en") $postElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[text()='Gmail']") _WD_ElementAction($sSession, $postElement, 'click') __WD_Post: URL=HTTP://127.0.0.1:9515/session/e0b3efcc1b2e90cfb38a4ea118e05f43/element; $sData={"using":"xpath","value":"//*[text()='Gmail']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"22ddb1f0-aaac-43ed-9779-b729ea13fcbd"}} Also, thank you for your help, but local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'Почта')]") returns __WD_Post: StatusCode=400; ResponseText=missing command parameters Link to comment Share on other sites More sharing options...
Danyfirex Posted July 6, 2018 Share Posted July 6, 2018 @slvtn666 It work for me the way I told you. https://prnt.sc/k3cnf7 an alternative could be: Local $sElement="" Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='gb_P']","",True) For $i=0 to UBound($aElements)-1 If _WD_ElementAction($sSession, $aElements[$i], 'text') ='Почта' Then $sElement=$aElements[$i] ExitLoop EndIf Next Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
slvtn666 Posted July 6, 2018 Share Posted July 6, 2018 4 hours ago, Danyfirex said: @slvtn666 It work for me the way I told you. https://prnt.sc/k3cnf7 What encoding do you use in SciTE? What encoding in your OS? Link to comment Share on other sites More sharing options...
Burgs Posted July 6, 2018 Share Posted July 6, 2018 OK great...thank you for the assistance ...regards Link to comment Share on other sites More sharing options...
Danyfirex Posted July 7, 2018 Share Posted July 7, 2018 @slvtn666 My SciTE encoding is UTF-8 and my OS is ISO 8859-1 Europa occidental. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
supperfake Posted July 7, 2018 Share Posted July 7, 2018 I try function _WD_Attach. This is my code #include "wd_core.au3" #include "wd_helper.au3" Local $hWnd = WinGetHandle("[CLASS:Chrome_WidgetWin_1]") Local $url = "http://google.com/" Local $sDesiredCapabilities SetupChrome() _WD_Startup() Local $Session=_WD_Attach($hWnd,"") Sleep(2000) _WD_Navigate($Session, $url) 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 but it does not work. I was wrong somewhere. Can you give me a example with _WD_Attach? Link to comment Share on other sites More sharing options...
Danp2 Posted July 7, 2018 Author Share Posted July 7, 2018 @supperfake You should take a look at the coding for _WD_Attach to get a better understanding of how it is intended to be used. P.S. It doesn't return a Session ID. You'll need to call _WD_CreateSession to obtain one of those. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danyfirex Posted July 8, 2018 Share Posted July 8, 2018 (edited) Hello. Here are two functions that we will allow us to highlight the element(s) we're using. expandcollapse popup; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_HighlightElement ; Description ...: ; Syntax ........: __WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $sElement - Element ID from _WDFindElement ; $iMethod - [optional] an integer value. Default is 1. ; 1=style -> Highlight border dotted red ; 2=style -> Highlight yellow rounded box ; 3=style -> Highlight yellow rounded box + border dotted red ; Return values .: Success - True ; Failure - False ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_HighlightElement($sSession, $sElement, $iMethod = 1) Local Const $aMethod[] = ["border: 2px dotted red", _ "background: #FFFF66; border-radius: 5px; padding-left: 3px;", _ "border:2px dotted red;background: #FFFF66; border-radius: 5px; padding-left: 3px;"] If $iMethod < 1 Or $iMethod > 3 Then $iMethod = 1 Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $sElement & '"}' Local $sResponse = _WD_ExecuteScript($sSession, "arguments[0].style='" & $aMethod[$iMethod - 1] & "'; return true;", $sJsonElement) Local $sJSON = Json_Decode($sResponse) Local $sResult = Json_Get($sJSON, "[value]") Return ($sResult = "true" ? SetError(0, 0, $sResult) : SetError(1, 0, False)) EndFunc ;==>__WD_HighlightElement ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __WD_HighlightElements ; Description ...: ; Syntax ........: __WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) ; Parameters ....: $sSession - Session ID from _WDCreateSession ; $aElements - an array of Elements ID from _WDFindElement ; $iMethod - [optional] an integer value. Default is 1. ; 1=style -> Highlight border dotted red ; 2=style -> Highlight yellow rounded box ; 3=style -> Highlight yellow rounded box + border dotted red ; Return values .: Success - True ; Failure - False ; @Extended Number of Highlighted Elements ; Author ........: Your Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __WD_HighlightElements($sSession, $aElements, $iMethod = 1) Local $iHighlightedElements = 0 For $i = 0 To UBound($aElements) - 1 $iHighlightedElements += (__WD_HighlightElement($sSession, $aElements[$i], $iMethod) = True ? 1 : 0) Next Return ($iHighlightedElements > 0 ? SetError(0, $iHighlightedElements, True) : SetError(1, 0, False)) EndFunc ;==>__WD_HighlightElements How to use: _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://google.com") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hplogo']") __WD_HighlightElement($sSession, $sElement) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='btnK']") __WD_HighlightElement($sSession, $sElement,2) Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='gb_P']", "", True) __WD_HighlightElements($sSession, $aElements,3) Sleep(10000) _WD_DeleteSession($sSession) _WD_Shutdown() Preview: Saludos Edited July 8, 2018 by Danyfirex mLipok and PoojaKrishna 2 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Danp2 Posted July 8, 2018 Author Share Posted July 8, 2018 @Danyfirex Thanks for the contribution. Some comments / questions -- You may want to modify to use the global $_WD_ELEMENT_ID What is your reasoning for making these internal use only? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danyfirex Posted July 8, 2018 Share Posted July 8, 2018 You're right I get the element value from the variable instead use the variable. I did internally because I was thinking in use it when debug flag is enable. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Danp2 Posted July 9, 2018 Author Share Posted July 9, 2018 My inclination would be to make these standard (rather than internal) functions that would be added to wd_helper.au3. That way they can be utilized as shown in your examples. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danyfirex Posted July 9, 2018 Share Posted July 9, 2018 As you wish is ok. ;-) adapt it to be consistent with the UDF. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
slvtn666 Posted July 9, 2018 Share Posted July 9, 2018 Hello everyone again! How to attach file via explorer? For example: I click on button 'attach file' on google image searcher, then window with explorer appears. Or this question no longer applies to Webdriver UDF? Link to comment Share on other sites More sharing options...
Danp2 Posted July 9, 2018 Author Share Posted July 9, 2018 Haven't done this myself, but I believe the best option here is to switch back to standard AutoIt commands to interact with the explorer dialog. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
slvtn666 Posted July 10, 2018 Share Posted July 10, 2018 (edited) @Danp2 WebDriver UDF compatible with older versions of webdriver? I'm trying to run your test with chrome v59 and chromedriver 2.28, but getting Webdriver exception without any information in log. Also chrome.log doesnt contains information about errors Edited July 10, 2018 by slvtn666 Link to comment Share on other sites More sharing options...
Danp2 Posted July 10, 2018 Author Share Posted July 10, 2018 56 minutes ago, slvtn666 said: @Danp2 WebDriver UDF compatible with older versions of webdriver? I'm trying to run your test with chrome v59 and chromedriver 2.28, but getting Webdriver exception without any information in log. Also chrome.log doesnt contains information about errors The UDF is designed to run with webdrivers supporting the current W3C standard. Please explain why you insist on testing with such out of date versions of Chrome / Chromedriver? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
PoojaKrishna Posted July 11, 2018 Share Posted July 11, 2018 Hi, I'm trying to get all information about a selected element on a chrome page using the UDF but for some elements the 'rect' command is not working with _WD_ElementAction when we call Get Element Rect. For working elements the response we receive looks like: {"value":{"height":96,"width":276,"x":545,"y":89}} And when it is an error it is like: {"value":{"error":"unknown error","message":"getting size failed to return y(Session infochrome=67.0.3396.99)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0135DF70+778096]\n\tOrdinal0 [0x0130B42D+439341]\n\tOrdinal0 [0x012E807F+295039]\n\tOrdinal0 [0x012B5D2D+89389]\n\tOrdinal0 [0x012C8349+164681]\n\tOrdinal0 [0x012B39C0+80320]\n\tOrdinal0 [0x012C8521+165153]\n\tOrdinal0 [0x012CF96B+194923]\n\tOrdinal0 [0x012C824F+164431]\n\tOrdinal0 [0x012B1B45+72517]\n\tOrdinal0 [0x012B2F2A+77610]\n\tOrdinal0 [0x012B2ECC+77516]\n\tGetHandleVerifier [0x013F9936+3478]\n\tOrdinal0 [0x013688C3+821443]\n\tOrdinal0 [0x01317066+487526]\n\tOrdinal0 [0x01317393+488339]\n\tOrdinal0 [0x013174A3+488611]\n\tOrdinal0 [0x0136AA67+830055]\n\tOrdinal0 [0x01316DAF+486831]\n\tOrdinal0 [0x013213FE+529406]\n\tOrdinal0 [0x0132C57B+574843]\n\tOrdinal0 [0x0132C6CD+575181]\n\tOrdinal0 [0x0132B92B+571691]\n\tBaseThreadInitThunk [0x76FC8484+36]\n\tRtlValidSecurityDescriptor [0x77E32FEA+282]\n\tRtlValidSecurityDescriptor [0x77E32FBA+234]\n"}} Any suggestion to solve this problem. My test code is attached below: expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include "misc.au3" #RequireAdmin $_WD_DEBUG = False _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Startup() $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}' Global $sSession = _WD_CreateSession($sDesiredCapabilities) If @Error Then msgbox(0,"Error", "Failed to create session." & @CRLF & "Select [Ok] to Exit") exit EndIf while (1) $sURL = InputBox("URL","Please enter the URL to navigate: ","https://w3c.github.io/webdriver/#dfn-getattribute") _WD_Navigate($sSession, $sURL) ;Navigate to URL ToolTip("Move mouse to the element and press Enter key") Local $hDLL = DllOpen("user32.dll") Do Sleep(100) Until _IsPressed("0D", $hDLL) ;Wait until user presses Enter key ToolTip("") $sElementId = _WD_GetMouseElement($sSession) ;Element id $sElementDetails = "ElementId: " & $sElementId & @CRLF If $sElementId Then __WD_HighlightElement($sSession, $sElementId, 1) $sCommand = 'name' $sRes = _WD_ElementAction($sSession, $sElementId, $sCommand, '') ;name If $sRes Then $sElementDetails = $sElementDetails & $sCommand & ": " & $sRes & @CRLF ;add to result $sCommand = 'text' $sRes = _WD_ElementAction($sSession, $sElementId, $sCommand, '');text If $sRes Then $sElementDetails = $sElementDetails & $sCommand & ": " & $sRes & @CRLF ;add to result $sCommand = 'rect' $sRes = _WD_ElementAction($sSession, $sElementId, $sCommand, '') ;rect If $sRes Then $sElementDetails = $sElementDetails & $sCommand & ": " & $sRes & @CRLF;add to result $Ret = Msgbox(1,"Result", $sElementDetails & @CRLF & "Select [Ok] to continue or [Cancel] to exit.") ;Display result If $Ret = 2 then ExitLoop Else Msgbox(0,"Not found", "Element id Not found") EndIf WEnd _WD_DeleteSession($sSession) _WD_Shutdown() duzers 1 Link to comment Share on other sites More sharing options...
Danp2 Posted July 11, 2018 Author Share Posted July 11, 2018 @PoojaKrishna This is an error being returned by chromedriver. Can you consistently reproduce this? If so, on which elements? P.S. You can check the value of @error after the call to _WD_ElementAction to determine if the call was successful Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
PoojaKrishna Posted July 11, 2018 Share Posted July 11, 2018 Quote This is an error being returned by chromedriver. Can you consistently reproduce this? If so, on which elements? Yes, please see the attached image. The high lighted element is the tested one. The error occurs for all elements on the page. My OS is windows 10 and Chrome version is: 67.0.3396.99 Thank you for the information, will check for @error after the calls. Link to comment Share on other sites More sharing options...
Recommended Posts