DevNoob Posted May 16, 2023 Share Posted May 16, 2023 Hello, I was wanting to use the 'wd_core.au3' and 'wd_helper.au3' libraries to locate a checkbox and do an action if it is checked or not (if not checked, check it and if it is unchecked) This is my script: $sStrategy = $_WD_LOCATOR_ByXPath $5Selector = "/html/body/div[2]/div[2]/div[2]/div/div/form/div[1]/div[2]/div[1]/input[1]" $sStartNodeID = Default $bMultiple = False $bShadowRoot = Default $sCheckboxID = _WD_FindElement($oSession, $sStrategy, $5Selector, $sStartNodeID, $bMultiple, $bShadowRoot) $sCoordinates = _WD_ElementAction($oSession, $sCheckboxID, 'property', 'rect') Local $sResponse = __WD_Get("exemple.com" & $sCheckboxID & "/" & 'property' & "/" & 'rect') Local $aResult = StringRegExp($sResponse, '"rect":({.*?})', 1) If IsArray($aResult) Then Local $sCoordinates = $aResult[0] ; Processar a string $sCoordinates para extrair as coordenadas ConsoleWrite("Coordinates is: " & $sCoordinates & @CRLF) EndIf But autoit only finds the element but gives an error: _WD_ElementAction ==> Success [0] : Parameters: Command=property Option=rect __WD_Get ==> Invalid value [4] : HTTP status = 0 Note: I use chrome version "113.0.5672.93 (Official Version) 64bit", and the driver is suitable for this version. Link to comment Share on other sites More sharing options...
Danp2 Posted May 16, 2023 Share Posted May 16, 2023 To toggle a checkbox, try clicking on it using _WD_ElementAction. See the DemoElements function in wd_demo for the correct way to retrieve an element's coordinates Not sure what you are trying to accomplish by calling __WD_Get, but this function is only intended to be used internally by the UDF itself. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Developers Jos Posted May 16, 2023 Developers Share Posted May 16, 2023 (edited) @DevNoob, Please do not cross post your question in multiple places! Your other post is removed. By the way: the same counts for soliciting for an answer by directly PMing members with the same question! Please read our forum rules on how we expect members to act around our forums. Thanks Edited May 16, 2023 by Jos DevNoob 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
DevNoob Posted May 16, 2023 Author Share Posted May 16, 2023 1 hour ago, Danp2 said: Para alternar uma caixa de seleção, tente clicar nela usando _WD_ElementAction. Consulte a função DemoElements em wd_demo para obter a maneira correta de recuperar as coordenadas de um elemento Não tenho certeza do que você está tentando realizar chamando __WD_Get, mas essa função deve ser usada apenas internamente pela própria UDF. I managed to make the coordinates appear through a java script, but when I try to pass the information I got from the script, to variables, it simply does not appear in the msg box, only what is written between the quotes: Local $result = _WD_ExecuteScript($oSession, "var element = document.querySelector('input[type=checkbox][name=EntP]'); if (element) { return JSON.stringify(element.getBoundingClientRect()); } else { return 'element not found'; }") If @error Then ConsoleWrite("An error occurred while executing the JavaScript script:" & @error & @CRLF) Else ConsoleWrite("The element directions are: " & $result & @CRLF) If $result <> "element not found" Then Local $resultJson = StringRegExpReplace($result, "[\\]{2}u([0-9a-fA-F]{4})", "\u$1") Local $decodedJson = ObjCreate("Scripting.Dictionary") $decodedJson = Json_Decode($resultJson, True) If @error Then ConsoleWrite("Ocorreu um erro ao decodificar o JSON: " & @error & @CRLF) Else Local $x = $decodedJson.Item("x") Local $y = $decodedJson.Item("y") Local $width = $decodedJson.Item("width") Local $height = $decodedJson.Item("height") MsgBox(0,"coord","coord x = "& $x & "coorde y = ") EndIf EndIf EndIf Link to comment Share on other sites More sharing options...
Danp2 Posted May 16, 2023 Share Posted May 16, 2023 You don't need to quote me when replying. If you do quote, please keep it in English. Please post code by using the proper toolbar icon so that your code is easier to read. As I previously mentioned, you should check out the DemoElements function, specifically this section of code -- ; Locate a single element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector) ; Get element's coordinates Local $oERect = _WD_ElementAction($sSession, $sElement, 'rect') If IsObj($oERect) Then ConsoleWrite("wd_demo.au3: (" & @ScriptLineNumber & ") : Element Coords = " & $oERect.Item('x') & " / " & $oERect.Item('y') & " / " & $oERect.Item('width') & " / " & $oERect.Item('height') & @CRLF) EndIf Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
DevNoob Posted May 16, 2023 Author Share Posted May 16, 2023 Rules and more rules, I already managed it myself, but thanks for updating me on the forum, you did that for sure. Link to comment Share on other sites More sharing options...
Danp2 Posted May 16, 2023 Share Posted May 16, 2023 No worries... I'll be sure to not respond to your posts in the future if that is what you prefer. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
DevNoob Posted May 16, 2023 Author Share Posted May 16, 2023 If I can do it without your help now, I can do it myself later, so no, you don't have to answer me. Link to comment Share on other sites More sharing options...
Danp2 Posted May 16, 2023 Share Posted May 16, 2023 TheXman 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Developers Jos Posted May 16, 2023 Developers Share Posted May 16, 2023 24 minutes ago, DevNoob said: If I can do it without your help now, I can do it myself later, so no, you don't have to answer me. I am sure your lack of English knowledge is in your way here as your are thinking we are not trying to help while we really are trying to and tell you what worlks best in these forums! The issue now is that due to this you seem to get mad and act very ungrateful !! No the best approach to get help but hey.... your choice! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now