Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
107 stars 21 forks source link

Support tables with non-standard table markers #481

Closed Danp2 closed 1 year ago

Danp2 commented 1 year ago

Feature request

Is your feature request related to a problem? Please describe

Originally discussed here. An example table can be viewed here.

Describe the solution you'd like

Enhance _WD_GetTable to support overriding of default table markers

Describe alternatives you've considered

Build separate function to support React tables

Additional context

mlipok commented 1 year ago

Should this be done with JS ?

Danp2 commented 1 year ago

@mlipok That wasn't the direction I was planning to go with this. I haven't looked at how _HtmlTableGetWriteToArray would work with this, but my initial thought was to add some optional parameters that allowed the calling routine to override the default xpaths that are used to get row / col counts and select the list of elements containing the target text.

Danp2 commented 1 year ago

I just took a look at _HtmlTableGetWriteToArray and quickly decided that it wouldn't make sense to modify it to allow the above. If we wanted to be compatible with this function, then we would need to translate the non-standard markers before calling _HtmlTableGetWriteToArray

Danp2 commented 1 year ago

@mlipok See #485 for pending PR. Here's the code that I've been using to test --

#include "wd_helper.au3"
#include "wd_core.au3"
#include "wd_capabilities.au3"

local $sCapabilities=SetupGecko("")
_WD_Startup()
local $sSession=_WD_CreateSession($sCapabilities)
local $url="https://glin.github.io/reactable/articles/examples.html"
_WD_Navigate($sSession,$url)
_WD_LoadWait($sSession)

$sTable = "(//div[@role='table'])[1]"
$sRows = "//div[@role='row']"
$sCols = "//div[@role='row']/div[@role='columnheader']"
$sCells = "//div[@role='cell' or @role='columnheader']"
$aTest1 = _WD_GetTable($sSession, $sTable, $sRows, $sCols, $sCells)

_ArrayDisplay($aTest1, "React Table")

$url="https://www.w3schools.com/html/html_tables.asp"
_WD_Navigate($sSession,$url)
_WD_LoadWait($sSession)

$sTable = "//table[@id='customers']"
$aTest2 = _WD_GetTable($sSession, $sTable)
_ArrayDisplay($aTest2, "Standard Table")

_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupGecko($bHeadless = False)
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)

    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'firefox')
    _WD_CapabilitiesAdd('browserName', 'firefox')
    _WD_CapabilitiesAdd('acceptInsecureCerts', True)
    ; REMARKS
    ; When using 32bit geckodriver.exe, you may need to set 'binary' option.
    ; This shouldn't be needed when using 64bit geckodriver.exe,
    ;  but at the same time setting it is not affecting the script.
    Local $sPath = _WD_GetBrowserPath("firefox")
    If Not @error Then
        _WD_CapabilitiesAdd('binary', $sPath)
        ConsoleWrite("wd_demo.au3: _WD_GetBrowserPath() > " & $sPath & @CRLF)
    EndIf

    If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless')
    _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupGecko
mlipok commented 1 year ago

Looks interesting.

Could you provide examples for: https://glin.github.io/reactable/articles/examples.html

Specifically: image

Danp2 commented 1 year ago

@mlipok That's the same table that is used in the code I posted above.

mlipok commented 1 year ago

Thanks. I was tired. Checked now and everything works fine. Green light as for me 👍