Jump to content
Danp2

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

Share this post


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

:(

Share this post


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

Share this post


Link to post
Share on other sites

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

 

Saludos

Share this post


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?

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

 

Saludos

Share this post


Link to post
Share on other sites

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?

Share this post


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

Share this post


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?

Share this post


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


 

Share this post


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

Share this post


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/201106-webdriver-udf-help-support-ii/
    • By Jgladden
      Dan - thanks for all that you do - this stuff is great. 
      Hoping you can assist with an issue we are having now that we have moved to Windows 10/Server 2016. The Chrome interactions were working flawlessly until moving over. Now my code fails when attempting to create the session. As you can see, our Chrome install is not in a standard location but I have validated the path to the binary. I have attached some detail below including system info, console output and the chrome log detail. I have tried several recommendations that have seen in various forums but none have made a difference
      Any assistance you can give would be greatly appreciated. 
      Thanks in advance, 
      chrome_Details.txt
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
×
×
  • Create New...