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

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

@Letraindusoir If I'm interpreting your question correctly, you are trying to retrieve the URL associated with a hyperlink. If so, then you might want to try something like this --

_WD_ElementAction($sSession, $sElement, 'attribute', 'href')

 

Share this post


Link to post
Share on other sites
Posted (edited)

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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 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_HighlightElement($sSession, $sElement[, $iMethod = 1]) _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession) WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ConsoleVisible($lVisible = False) 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/192730-webdriver-udf-help-support/
    • By Davidowicza
      Hey guys,
      I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start...
      I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML)
      Element I need to select:
      This is the Xpath for the last 3 instances of chrome I have run the script with:
      //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time.
      How I am trying to select the element:
      ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick()
      Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution.
      Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can.
    • By daluu
      This is kind of already posted here:
      '?do=embed' frameborder='0' data-embedContent>>
      but wanted to note this in this forum of example scripts in case some people only look in this forum for examples and not the other forums with respect to AutoIt integration or relation to Selenium WebDriver.
      So, the example in summary is: you can use Selenium WebDriver API to do AutoIt GUI automation (the ControlXyz() and WinXyz() functons, along with mouse and "send keys" functions). Although I suppose that might be opposite or counter to what most examples here are about - using AutoIt to do or control other stuff rather than using other stuff to control/run AutoIt. But regardless, it is an example implementation of a different use case for AutoIt beyond the general AutoIt community, like those who also use Selenium WebDriver and/or need to integrate Selenium with AutoIt for remote deployment.
      https://github.com/daluu/AutoItDriverServer
      with specific demo examples here:
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/CalculatorTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
×
×
  • Create New...