Jump to content

WebDriver UDF - Help & Support


Recommended Posts

@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

Link to post
Share on other sites
  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

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.

use the _WD_ElementAction function like this: $sValue = _WD_ElementAction($sSession, $sElement, 'attribute', 'src') p.s. ... and remove @src from the xPath: "//img[@alt='NiceGirl']"

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 fun

Posted Images

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 post
Share on other sites

@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

Link to post
Share on other sites

@slvtn666 My SciTE encoding is UTF-8 and my OS is ISO 8859-1 Europa occidental.

 

Saludos

Link to post
Share on other sites

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 post
Share on other sites

Hello. Here are two functions that we will allow us to highlight the element(s) we're using.

; #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:

Screenshot_2.thumb.png.9f9bcc340eae704d886e75653f499911.png

 

Saludos

Edited by Danyfirex
Link to post
Share on other sites

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

Link to post
Share on other sites

As you wish is ok. ;-) adapt it to be consistent with the UDF.

 

Saludos

Link to post
Share on other sites

@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 by slvtn666
Link to post
Share on other sites
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?

Link to post
Share on other sites

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:

#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()


 

Link to post
Share on other sites
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.

 

Error.png

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By goku200
      I am trying to change the settings of the print option to Save as PDF and its not changing the settings and clicking on the Save button at the bottom. Here is my script that I have written and the format is correct below. Chrome browser I'm using is 97.0 My script was working fine using Chrome 95.0\ Not sure why its not working now
      It finds the print-preview-app element but not the others.
       
    • By goku200
      I am trying to hit the Return key without having to use the Send keys. I have the following code and its not hitting the Return key. Am I missing something?
      ; Press Return $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE006"},' ; Pause $sAction &= '{"type": "pause", "duration": 500},' ; Release Return $sAction &= '{"type": "keyUp", "value": "\uE006"}]}]}' _WD_Action($sSession, "actions", $sAction)  
    • By goku200
      I'm having an issue with my html paginated table. The script work as expected. It reads the html table and clicks on the Download button. However when it clicks on the next page its not iterating the items. instead it goes to the next URL from the spreadsheet and then iterates through the html table clicking the Download button and so on. Not sure why its doing that. I want it to click the next page and then continue iterating then after it has reached the end of the pagination go to the next url in the spreadsheet and repeat the process. Below is my script. Any help is appreciated 🙂
       
       
    • By goku200
      I'm having some issues with my script that's not grabbing the id from the cell and appending it to the url test that I have in my script.
      Here is my script:
      What I'm having issues is looping through the id column in the excel spreadsheet and adding 1 to the url address when its tabbed by using _WD_NewTab. When it goes to the browser I'm wanting it to display: https://127.0.0.1/test.html?id=1 press Enter and save the file as 1.html and so forth for the others. Not sure what I'm doing wrong here. 
       
×
×
  • Create New...