Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

On 5/23/2019 at 11:37 PM, Danp2 said:

Take a look at the DemoActions function in wd_demo.au3 for an example of moving the mouse pointer to an element.

As far as giving an element focus, just setting its value with _WD_ElementAction should be enough. You could send it a click with _WD_ElementAction as well.

Thanks Danp2 !

I have solved this problem with the help of _WD_ExecuteScript and javascript.

Share this post


Link to post
Share on other sites

Dear Danp2 , can you do a tool like Au3Info.exe In free time? through WYSIWYG mode,we can automatically get the Xpath and the attributes of the element when place the mouse in the location of the element of the page. It feels a little troublesome and not too convenient to use browser developer tools.

Only a master like you can make such a tool.:)

Share this post


Link to post
Share on other sites
16 hours ago, Letraindusoir said:

Dear Danp2 , can you do a tool like Au3Info.exe In free time? through WYSIWYG mode,we can automatically get the Xpath and the attributes of the element when place the mouse in the location of the element of the page. It feels a little troublesome and not too convenient to use browser developer tools.

Only a master like you can make such a tool.:)

You could try this visual tool to get "selectors" of DOM objects: https://www.autoitscript.com/forum/topic/195777-ie-dom-elements-visual-selector-tool/
The selectors obtained by this tool can be used in this WebDriver UDF.
Example:
suppose you store in the variable $sMyCssSelector the string of the CSS selector retrieved with the above visual tool, you can then use that variable in the  _WD_FindElement function() in this way:
$RefElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector,  $sMyCssSelector)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
2 hours ago, Chimp said:

You could try this visual tool to get "selectors" of DOM objects: https://www.autoitscript.com/forum/topic/195777-ie-dom-elements-visual-selector-tool/
The selectors obtained by this tool can be used in this WebDriver UDF.

Thank you, Chimpp! I did not register this forum for a long time, read a limited number of posts, did not pay attention to the forum already has such a convenient tool. Thank you very much for taking note of this post and recommending similar excellent tools

Share this post


Link to post
Share on other sites

please,How do I get the Src-Url of an anchor link?

use "_WD_ElementAction($sSession,$Element_Link, 'value', '')" don't work....

Edited by Letraindusoir

Share this post


Link to post
Share on other sites

Thank Danp2! What is the '$sOption' parameter in "_ WD_ElementAction ($sSession, $sElement, $sCommand, $sOption)" and where can I refer to it?

There are probably some concepts that I'm not very clear about. Is $sElement a dom object?

Edited by Letraindusoir

Share this post


Link to post
Share on other sites
Func _WD_Action($sSession, $sCommand, $sOption = '')
    Local Const $sFuncName = "_WD_Action"
    Local $sResponse, $sResult = "", $iErr, $sJSON, $sURL

    $sCommand = StringLower($sCommand)
    $sURL = $_Glo_BASE_URL & ":" & $_Glo_PORT & "/session/" & $sSession & "/" & $sCommand

    Switch $sCommand
        Case 'back', 'forward', 'refresh'
            $sResponse = __WD_Post($sURL, '{}')
            $iErr = @error

Could it be changed to:

Func _WD_Action($sSession, $sCommand, $sOption = '')
    Local Const $sFuncName = "_WD_Action"
    Local $sResponse, $sResult = "", $iErr, $sJSON, $sURL

    $sCommand = StringLower($sCommand)
    $sURL = $_Glo_BASE_URL & ":" & $_Glo_PORT & "/session/" & $sSession & "/" & $sCommand

    Switch $sCommand
        Case 'back', 'forward', 'refresh','stop'
            $sResponse = __WD_Post($sURL, '{}')
            $iErr = @error

so, I can use "_WD_Action($sSession, 'stop')" to Stop the web-page being loaded?

Edited by Letraindusoir

Share this post


Link to post
Share on other sites

@Letraindusoir The UDF is designed to implement the functionality of the webdriver specs. I'm not aware of 'stop' being a valid option to submit to the webdriver, so I suspect the webdriver would return an error if you attempted this.

As far as your question regarding $sOption, this can contain many different values depending on your usage at the time. It's beyond the scope of this thread / UDF to document all of the various attributes, properties, etc that can be retrieved here.

Share this post


Link to post
Share on other sites

By the way, if I want a more convenient way,Is there a function From webdiver that is functionally equivalent to '_IETableWriteToArray' and '_IEFormElementGetCollection'?

Share this post


Link to post
Share on other sites

Because I am used to some of the functions and methods of "IE.au3", I am used to the way of "object.method" or "object.property", so I often understand it by comparing with each other.

Share this post


Link to post
Share on other sites
11 minutes ago, Letraindusoir said:

_IEFormElementGetCollection

I believe this can already be done with _WD_FindElement (use $sStartElement with $lMultiple = True)

Quote

_IETableWriteToArray

This functionality hasn't made it to the UDF yet. @danylarson did some initial work here and also later in the same thread.

Share this post


Link to post
Share on other sites
3 hours ago, Letraindusoir said:

By the way, if I want a more convenient way,Is there a function From webdiver that is functionally equivalent to '_IETableWriteToArray' and '_IEFormElementGetCollection'?

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 function fits very well to be used with the webBrowser udf. Just save the _HtmlTable2Array.au3 and #include it in your listing.
here a simple example of use (I'm using IE here, but of course you can change settings to let the WebDriver use your preferred browser)

; Open a web page with a table, get a reference to the first table
; on the page (index 0) and read its contents into a 2-D array

#include <Array.au3>
#include 'wd_helper.au3'

#include '_HtmlTable2Array.au3' ; <- get it from blow link
; https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/

; === setup WebDriver for IE ===============
$_WD_DEBUG = False
Global $sDesiredCapabilities
Global $sSession

_SetupIE()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
; ==========================================

_Example_TableWriteToArray()

Func _Example_TableWriteToArray()

    ; -- open a web page containing a table (ok also if there are more tables)
    _WD_Navigate($sSession, "https://www.beginnersguidetohtml.com/guides/html/tables/complex-tables")

    ; get a 'list' of the tables in the page
    $aTables = _WD_FindElement($sSession, $_WD_LOCATOR_ByTagName, "table", '', True)

    ; get the HTML source of the first table (index 0) change index if you need another table
    $sTable_HTML_source = _WD_ElementAction($sSession, $aTables[0], 'property', 'outerHTML')

    Local $aMyTable
    ; ------------------------------------------------------------------------------------
    ; the _HtmlTableWriteToArray() function extract the data content from the HTML source
    ; and save data in a 2d Array. (if second parameter is true it fill cells of the array
    ; corresponding to the span areas with spanned data (data is spread over the cells)
    ; ------------------------------------------------------------------------------------
    $aMyTable = _HtmlTableWriteToArray($sTable_HTML_source)
    _ArrayDisplay($aMyTable, "Data without spread")

    $aMyTable = _HtmlTableWriteToArray($sTable_HTML_source, True)
    _ArrayDisplay($aMyTable, "Data spreaded")
    ; ------------------------------------------------------------------------------------
EndFunc   ;==>_Example_TableWriteToArray

Func _SetupIE()
    _WD_Option('Driver', 'IEDriverServer.exe')
    _WD_Option('Port', 5555)
    _WD_Option('DriverParams', '--log-file=' & @ScriptDir & '\IE.log')
    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc   ;==>_SetupIE

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
20 hours ago, Danp2 said:

I believe this can already be done with _WD_FindElement (use $sStartElement with $lMultiple = True)

This functionality hasn't made it to the UDF yet. @danylarson did some initial work here and also later in the same thread.

Many thanks,Dan !

Share this post


Link to post
Share on other sites
16 hours ago, Chimp said:

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 function fits very well to be used with the webBrowser udf. Just save the _HtmlTable2Array.au3 and #include it in your listing.
here a simple example of use (I'm using IE here, but of course you can change settings to let the WebDriver use your preferred browser)

Thanks,Chimp !

Share this post


Link to post
Share on other sites

_WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False)
Are there any actual examples where '$sStartElement' is not empty? I don't quite understand when $sStartElement is used....

Share this post


Link to post
Share on other sites

Does anyone can help me to understand how to click on element using right mouse button (contextclick)?

I have tried this code (according to what I found in this thread and wd_demo.au3)

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@data-original-title="data 1"]|//a[@title="data 1"]', '', True)

    If @error = $_WD_ERROR_NoMatch Then
;       _TrayTip('Nothing found!')
    Else
        For $aElement in $aElements
;           _TrayTip('Going to click item...')
            _WD_ElementAction($sSession, $aElement, 'click')
            Sleep(1000)
        Next
    EndIf

    $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//a[@data-original-title="data 2"]|//a[@title="data 2"]', '', True)
    If @error = $_WD_ERROR_NoMatch Then
        _TrayTip('Nothing found!')
    Else
        For $aElement in $aElements
            _TrayTip('Going to right-click item...')
            Local $sAction
            $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
            $sAction &= $aElement & '","' & $_WD_ELEMENT_ID & '":"' & $aElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}'
            _WD_Action($sSession, "actions", $sAction)
            sleep(2000)
            _WD_Action($sSession, "actions")
            sleep(2000)
        Next
    EndIf

But right click doesn't "goes" to desired element. I got context menu opened on coordinates x:0 y:0 of document (page). Please, advice.

UPD, Now I see my mistake. I was trying to use "$sElement" but my object is "$aElement". All works well now. Sorry for bothering 😎

Edited by MONaH-Rasta
Found a problem

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/
      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/ Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession[, $sjQueryFile = Default[, $iTimeout = Default]]) _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ElementSelectAction($sSession, $sSelectElement, $sCommand) _WD_ConsoleVisible($lVisible = False) _WD_LoadWait($sSession[, $iDelay = 0[, $iTimeout = -1[, $sElement = '']]]) _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1) _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) _WD_GetShadowRoot($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_IsLatestRelease() _WD_UpdateDriver($sBrowser[, $sInstallDir = Default[, $lFlag64 = Default[, $lForce = Default]]]) _WD_DownloadFile($sURL, $sDest) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      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 JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
    • By svenjatzu
      hey hi
      someone please can help me translate my code to be valid for udf webriver?
       
      #RequireAdmin Opt("WinTitleMatchMode",2) ;~ Sleep(10000) ShellExecute("C:\neu\1.lnk") ;~ Sleep(3000) ;~ $PID = ShellExecute("C:\freeneu\tab.exe") ;~ Sleep(30000*5) WinWait("Example Domain - Iron","") Global $sWinTitle = "Example Domain - Iron" Global $avWinList = WinList($sWinTitle) While $avWinList[0][0] < 1 Sleep(250); Wait for new process to create its GUI $avWinList = WinList($sWinTitle) WEnd For $n = 1 To $avWinList[0][0] WinActivate($avWinList[$n][1]) WinMove($avWinList[$n][1], "", 0, 0, 230, 440) Next Opt("WinTitleMatchMode",1) WinWait("Iron") Sleep(5333) WinWait("Iron") Opt("WinTitleMatchMode",2) WinWaitActive("m:") WinWait("m:") WinClose("m:") ;~ Sleep(5000) Sleep(1000) ;~ ProcessClose("tab.exe") ShellExecute(@ScriptDir & "\q2.exe")  
    • By water
      Internet Explorer is nearly dead, newer versions of Firefox can't any longer be automated using Stilgar's FF UDF.
      Hence more and more users (including me) need to look at automating Webbrowsers using WebDriver.
      That's why I have started to create a tutorial in the wiki.
      It should describe all necessary steps from intallation to usage.

      I'm still collecting ideas for the tutorial - that's where you come into play.
      What do you expect to see in such a tutorial?
      Which browsers should be covered (Firefox, Chrome and Edge are settled)? Any questions for the FAQ? Which (high level) coding examples do you expect (like "How to attach to a running browser instance") ... Like to see your comments
       
      ToDo-List:
      Add "Tools" section and add ChroPath plugin. Done. FAQ: "How to attach to a running browser instance". Done. Explain the difference between iuiautomation, iaccessible, autoit, webdriver. Done. The AutoIt FAQ 40 has been extended. Detailed description of each function. Done Example for "how to deal with downloading". Use function _WD_DownloadFile. Example for "how to deal with popups (alerts, print or save dialog). Use function_WD_AlertRespond to respond to a user prompt. Example for "how to deal with multiple tabs". Use functions _WD_NewTab (create a new tab), _WD_Window (close or switch to a tab) and _WD_Attach (attach to existing tab).
    • By water
      The WebDriver UDF provides a toolbox full of functions to facilitate automating Web browsers.
      Still scripts can become quite complex.
      In this thread users can post "real life" examples to show how specific tasks can be implemented.
      Note
      When posting an example please describe the purpose of the script and the WebDriver functionality used!
       
×
×
  • Create New...