Jump to content

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.

Link to comment
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.:)

Link to comment
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)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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

Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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 !

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...