Jump to content

WebDriver UDF - Help & Support (IV)


Recommended Posts

16 minutes ago, SOLVE-SMART said:

Hmm, you only need the values of the <span> tags inside the <td> tags, am I right?

and in tag <p>

16 minutes ago, SOLVE-SMART said:

Is it a public page (URL) or can you share more of the DOM?

No (
Sven, thank you very much for your help. I have solved this problem. I got all the values I needed. I got about 300 lines of code. Now my task is to optimize the number of requests to the page. Now there are 2+ per cell for complex ones up to 20. And the cells are 1200.
So I'm looking for a way to take the whole table as text, with one outerHTML query, and then process that table as text, using XPath. That's why I need this function of working with strings in variables via XPath.  I've already found and tested the keys themselves for Xpath, and the code works.

Link to comment
Share on other sites

Alright @dadLog,

understood 👍 . Nice that you could solve your problem.
In the meanwhile I faked a table by DOM changes, with your <td> snippet and tried simple '//td//span' which gets all elements separated by \r\n.

image.thumb.png.63035781f5be4d6f18d50403fd3ea1f9.png

I am sure you know and already use _WD_FindElement ($bMultiple = True) to get all the <span> and <p> tags at once.
Anyway, maybe it's not relevant anymore, but browser extensions like SelectorsHub are pretty helpful for first and short tests.

 

24 minutes ago, dadLog said:

[...] I've already found and tested the keys themselves for Xpath, and the code works.

If you can and want to, I would like to see and understand your approach. Maybe I can learn about it too 😇 .
If not, all fine.

Update: XPath for your <span> and <p> tags => '(//td//span | //td//p)'.

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

One last thing I want to mention @dadLog:
Have a look at the xml.au3 which supports XPath search as far as I know.

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Func _GrabPageTable (ByRef $asNamesSection , ByRef $asParametrsSection , $sTabName )
; $sTabName the prameter can be 'Active' 'Completed' or 'Booked'
; $asNamesSection[$i] , will be names of all sections, in our case they are numbers of lots , [$i] - number of row in the table
; $asParametrsSection[$i][] will be parameters from all sections, their values [$i] is the number of line on the start page in the table
, write data from the table to the file ; at first we look for the table and get an array of rows in $oElementS, search through the rows and write them into $sFileINIFullPath
    Local $oElementS , $sElement , $iErrStatus , $iRowsCount, $iColCount, $sFileINIFullPath , $sElementTable
    Local $sCell , $sContents , $iError , $iNumber , $sPathForLog , $sTableXPath , $sTrXPath , $sTdXPath
    Local $asDataINISection[14][2] , $iNumberOfParametrs = 12 ; The 13th parameter - 'Duplicate found. Time' is created if necessary
    $asDataINISection[0][0] = $iNumberOfParametrs

    $sTableXPath = "//table[@class='MuiTable-root']"
    _WD_WaitElement ($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTableXPath , Default , 15000 , $_WD_OPTION_Visible )
    $iError = @error
    If $iError Then _MsgBoxAndExit (4096+16, '_SetNumberRowsPage , debug line ~' & @ScriptLineNumber , 'Waiting for XPAth element="'&$sTableXPath&'" , the table should appear within 15 seconds, but _WD_WaitElement ($_WD_OPTION_Visible) ended with error = '& $iError)

    $sPathForLog = $sTableXPath & ' --> '
    $sElementTable = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTableXPath) ; start element for searching strings - I wanted to use
    $sTrXPath = "./tbody/tr[contains(@class,'MuiTableRow-root')][contains(@class,'MuiTableRow-hover')]"
    $sPathForLog = $sPathForLog & $sTrXPath & ' --> '
    ; we select an element relative to $IDtable, so the first character in front - "." is the same as self:: - returns the current element
    Get the array $oElementS, which will consist of elements - table rows
    $oElementS = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTrXPath , $sElementTable , 'True' )
    $iErrStatus = @error
    $iRowsCount = UBound ( $oElementS, 1 ) ; determine the dimension of the array, the result = the number of lines on the page in the table
    ReDim $asNamesSection [ $iRowsCount+1 ]
    ReDim $asParametrsSection [ $iRowsCount+1 ][ 12+1 ] ; we increase by 1 the dimensionality to start with [1] instead of [0]
    $asNamesSection [0] = $iRowsCount
    $asParametrsSection [0][0] = $iRowsCount ; in [0] we put the arrays themselves

    ProgressOn ('Read rows from table', 'URL = [' & $sURL & "]', 'Read row # [0]. Total on page [" & $iRowsCount & "] rows" , Default , Default , 16) ; initialize the progress indicator
    For $i = 1 To $iRowsCount
        ProgressSet ( 100* $i / $iRowsCount , "Reading row # [" & $i & "]. Total on page [" & $iRowsCount & "] rows" ) ; initialize the progress indicator
        ; take the row from the table
        $sElement = $oElementS[$i-1] ; because the numbering of elements in the array starts from 0
            
        ; cell 1 - "Lot"
        $sTdXPath = "./td[1]/span"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
        ;Assume that the first cell "lot" contains only digits and will be used as ID , check IsNumber() must return 0
        $iNumber = _OnlyDigitInText ($sContents ) ; we discard everything except the numbers but do not convert them into a number so that we leave the zeros at the beginning of the line check if string has not changed after deleting NUMERICS. Probably, there were zeros at the beginning, like in the time sheet number; that is why we will not convert it into a number
        If $iNumber <> $sContents Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , value must be an integer, used as lot number.')
        $asNamesSection [$i] = $sContents ; we record the section name as well as the lot name

        ; cell 2 - "Status"
        $sTdXPath = "./td[2]/div"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
;~ IniWrite ( $sFileINIFullPath, $idRace , "Status" , $sContents )
        $asParametrsSection [$i][1] = $sContents ; Parameter name "Status"

        ; Cell 3 - "Checks"
        $sTdXPath = "./td[3]/div/img"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        $sContents = ''
        If Not $iError Then
            $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'ATTRIBUTE' , 'alt')
            ;$sContents = _WD_ElementAction($WD_SESSION, $sCell, 'property' , 'innerHTML')
            $iError = @error
            If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
    ;~ IniWrite ( $sFileINIFullPath, $idRace , "Notes" , $sContents )
        EndIf
        $asParametrsSection [$i][2] = $sContents ; The name of the parameter "Marks"

        ; Cell 4 - "Route-from-where."
        $sTdXPath = "./td[4]/div[1]/div[1]/div[1]/p"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
;~ IniWrite ( $sFileINIFullPath, $idRace , "Route-fromwhere" , $sContents )
        $asParametrsSection [$i][3] = $sContents ; The name of the parameter "Route-fromwhere"

        ; cell 4 - "Loading time"
        $sTdXPath = "./td[4]/div[1]/div[1]/div[1]/span"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
;~ IniWrite ( $sFileINIFullPath, $idRace , "loading time" , $sContents )
        $asParametrsSection [$i][4] = $sContents ; The parameter name is "Loading Time"

        ; Cell 4 - "Route to where"
        $sTdXPath = "./td[4]/div[1]/div[1]/div[2]/p"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
;~ IniWrite ( $sFileINIFullPath, $idRace , "Route-where" , $sContents )
        $asParametrsSection [$i][5] = $sContents ; The name of the parameter "Route to Where"

        ; Cell 4 - "Unloading time"
        $sTdXPath = "./td[4]/div[1]/div[1]/div[2]/span"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
;~ IniWrite ( $sFileINIFullPath, $idRace , "Unloading time" , $sContents )
        $asParametrsSection [$i][6] = $sContents ; The parameter name is "Unloading Time"

        ; Cell 5 - "Tonnage"
        $sTdXPath = "./td[5]/span"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
        $iNumber = _OnlyDigitInText ($sContents)
        $iNumber = Number ($iNumber )
        If Not IsNumber($iNumber) Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , after conversion to number =['& $iNumber &'] value type = ['& VarGetType($iNumber) &'], expected NUMBER!")
;~ IniWrite ( $sFileINIFullPath, $idRace , "Tonnage" , $iNumber )
        $asParametrsSection [$i][7] = $iNumber ; The name of the parameter "Tonnage"
        
            ; cell 6 - "Number of pds.
        $sTdXPath = "./td[6]/span"
        $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
        $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
        $iError = @error
        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
        $iNumber = _OnlyDigitInText ($sContents)
        $iNumber = Number ($iNumber )
        If Not IsNumber($iNumber) Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , after conversion to number =['& $iNumber &'] value type = ['& VarGetType($iNumber) &'], expected NUMBER!")
;~ IniWrite ( $sFileINIFullPath, $idRace , "Number of subs" , $iNumber )
        $asParametrsSection [$i][8] = $iNumber ; The name of the parameter "Number of Rounds" Table cells on the tabs 'Active', 'Completed' and 'Booked' are differentiated according to their order and contents starting from the 7

        Switch $sTabName
            Case 'Active' ; cell 7 Base value - 'Active' tab
                ; Cell 7 - 'Base Value' - 'Active' tab
                $sTdXPath = "./td[7]/p"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                $iNumber = 0 ; "Base value" may not exist, initialize with zero
                If Not $iError Then
                        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                        $iError = @error
                        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
                        $iNumber = _OnlyDigitInText ($sContents)
                        $iNumber = Number ($iNumber )
                        If Not IsNumber($iNumber) Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , after conversion to number =['& $iNumber &'] value type = ['& VarGetType($iNumber) &'], expected NUMBER!")
                EndIf
                $asParametrsSection [$i][9] = $iNumber ; The name of the parameter "Base Cost"

                ; Cell 8 - "Current Value" - 'Active' tab
                $sTdXPath = "./td[8]/p"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                $iNumber = 0 ; "The current cost" may be absent, initialize with zero
                If Not $iError Then
                        $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                        $iError = @error
                        If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
                        $iNumber = _OnlyDigitInText ($sContents)
                        $iNumber = Number ($iNumber )
                        If Not IsNumber($iNumber) Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , after conversion to number =['& $iNumber &'] value type = ['& VarGetType($iNumber) &'], expected NUMBER!")
                EndIf
                $asParametrsSection [$i][10] = $iNumber ; The name of the parameter "Current Value"
                
                
                ; cell 4 - "Route - Note"
                $sTdXPath = "./td[4]/div[1]/div[2]/span"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
                $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                $iError = @error
                If $iError Then $sContents = '' ; if there is no text, write a blank value
                ;If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '' but could not get its text, error code = ' & $iError )
                $asParametrsSection [$i][11] = $sContents ; The name of the 'Route-Note' parameter


            Case 'Completed' ; cell 7 Base Value - tab 'Completed'
                ; Cell 7 - 'Driver' - 'Completed' tab
                $sTdXPath = "./td[7]/span"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
                $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
                $asParametrsSection [$i][9] = $sContents ; Parameter name "Driver"

                ; Cell 8 - "Confirmation Date" - 'Completed' tab
                $sTdXPath = "./td[8]/time"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
                $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
                $asParametrsSection [$i][10] = $sContents ; The name of the "Confirmation Date" parameter

                    ; cell 9 - "Cost" - 'Completed' tab
                $sTdXPath = "./td[9]/p"
                $sPathForLog = $sTableXPath & ' --> ' & $sTrXPath & ' --> ' & $sTdXPath
                $sCell = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sTdXPath , $sElement )
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Trying to select on tab ['& $sTabName & '] in table on line [' & $i & '] get cell as element XPath = "' & $sPathForLog & '" but _WD_FindElement() gave error = ' & $iError )
                $sContents = _WD_ElementAction($WD_SESSION, $sCell, 'text')
                $iError = @error
                If $iError Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'Successfully selected on tab ['& $sTabName & '] in table on line [' & $i & '] element XPath = "' & $sPathForLog & '" but could not get its text, error code = ' & $iError )
                $iNumber = _OnlyDigitInText ($sContents)
                $iNumber = Number ($iNumber )
                If Not IsNumber($iNumber) Then _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'On tab ['& $sTabName & '] in table on line [' & $i & '] successfully got text from element XPath = "' & $sPathForLog & '" , text =[' & $sContents & '] , after conversion to number =['& $iNumber &'] value type = ['& VarGetType($iNumber) &'], expected NUMBER!")
                $asParametrsSection [$i][11] = $sContents ; The name of the "Cost" parameter

            Case Else ; argument in the function does not match 'Active' or 'Completed'
                _MsgBoxAndExit (4096 + 16, '_GrabPageTable , debug line ~' & @ScriptLineNumber, 'An invalid argument ['& $sTabName & '"] was passed to the function. Expected to be 'Active' or 'Completed'").

        EndSwitch

        ; records the time the record was created, and if it is already present, the time the record was last detected - 'Duplicate record detected'
        $asParametrsSection [$i][12] = @YEAR & '-' & @MON & '-' & @MDAY & '--' & @HOUR & ':' & @MIN & ':' & @SEC ; The name of the "Creation Time" parameter

    Next
    ProgressOff ( )

    If $iTotalCountRows = 'Variable not set' Then   $iTotalCountRows = _GetCountRowsInTable ($sTabName)
    ; the number of rows worked out from the table since the current table starts, it is reset to zero when the table is changed
    $iCountRow += $iRowsCount
EndFunc

 

Link to comment
Share on other sites

Oh wow @dadLog,

what a script 😲 . Don't get me wrong, but I like to recommend you to split several parts of your function in extracted functions. Otherwise it could (will) go crazy if you try to understand your approach in a month or so.

I also do not understand your way of logging => _MsgBoxAndExit() with all the information about what is wrong with the XPath and findings etc.
If you want more output you can set the log level of the WebDriver (to $_WD_DEBUG_Full).

_SetLogLevel()

Func _SetLogLevel()
    ; $_WD_DEBUG = $_WD_DEBUG_None  ; no logging
    ; $_WD_DEBUG = $_WD_DEBUG_Error ; logging in case of Error
    ; $_WD_DEBUG = $_WD_DEBUG_Info  ; logging with additional information
    ; $_WD_DEBUG = $_WD_DEBUG_Full  ; logging with full details for developers

    $_WD_DEBUG = $_WD_DEBUG_Full
EndFunc

If you need more support, don't hesitate to ask 🤝 .

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

4 minutes ago, SOLVE-SMART said:

Don't get me wrong, but I like to recommend you to split several parts of your function in extracted functions. Otherwise it could (will) go crazy if you try to understand your approach in a month or so.

Thanks for the tips and help! I am aware of the fact that my code is naive and imperfect. I gratefully accept suggestions for improvement.

 

6 minutes ago, SOLVE-SMART said:

I also do not understand your way of logging => _MsgBoxAndExit() with all the information about what is wrong with the XPath and findings etc.
If you want more output you can set the log level of the WebDriver (to $_WD_DEBUG_Full).

This is not a way of logging. it is a temporary stub for an exit with a description of what caused the exit. Subsequently it will be split into 2 parts exit and restart with the reason logged.

 

8 minutes ago, SOLVE-SMART said:

If you need more support, don't hesitate to ask

I'm trying to look at examples ( xml.au3 ), but it's hard because of my problems with English. ( 

Thank you,  Sven!

Link to comment
Share on other sites

Hi @iSan,

try this to get the elements:

Global $aElements = _FindElements('//tr')

_ArrayDisplay($aElements)

Func _FindElements($sSelector)
    Return _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, Default, True)
EndFunc

or this to get the count of the found elements:

MsgBox('', 'Count of found elements', _GetElementsCount('//tr'))

Func _FindElements($sSelector)
    Return _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, Default, True)
EndFunc

Func _GetElementsCount($sSelector)
    Return UBound(_FindElements($sSelector))
EndFunc

Please provide your tryouts/your code next time, thanks. 🤝

Best regards
Sven

________________
Stay innovative!

 

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

1 minute ago, iSan said:

@SOLVE-SMARToh that so easy, i need take a look at UBound 

Thank you Sven

You're welcome 😀 .

Please notice, that I updated my last post (it's better understandable now).

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

How can i click to a <span with special characters like this.

<span style="color:#444444;cursor:pointer;" onclick="$find('LoginExtender')._login(true);">Héllo</span>

i tried: 

_WD_LinkClickByText($sSession, 'Héllo')

And copy xpath:

 

_WD_ClickElement($sSession, "span//[@id='LoginExtender_Attention']/div/span")

And how to hide/visible Chromedriver.exe

Link to comment
Share on other sites

2 minutes ago, iSan said:

And how to hide/visible Chromedriver.exe

That is covered in the wiki FAQ section (see link in my sig)

Quote

How can i click to a <span with special characters like this.

You can't use _WD_LinkClickByText for this because this function is limited to <a> link elements. Your custom _WD_ClickElement should work as long as the xpath is correct.

Link to comment
Share on other sites

I'm stuking in some staffs like this:

- Clear or SetValue in a Input id with text="01/01/2023" there are some special character / or .

<input id="ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct" onfocus="$df.focus(this);" onblur="$df.blur(this);" onkeypress="$df.keypress(event, this, 'ngay_lct');" style="text-align: left; width: 77px;" ondrop="return false" spellcheck="false" autocomplete="off" class="FormInput FormTextInput" type="text" value="  /  /    " oncontextmenu="$func.showContextMenu(event, this, 'v', false);return false;" text="04/01/2023">

-And one thing. I find out 11 Elements, i can show the Elements[10] but when i use it for _WD_ElementAction, i got Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Don't even understand 😕

Link to comment
Share on other sites

Dear @Danp2 

Please help me check that.

I have an <input id show below. The xpath is OK.

<input id="ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct" onfocus="$df.focus(this);" onblur="$df.blur(this);" onkeypress="$df.keypress(event, this, 'ngay_lct');" style="text-align: left; width: 77px;" ondrop="return false" spellcheck="false" autocomplete="off" class="FormInput FormTextInput" type="text" value="  /  /    " oncontextmenu="$func.showContextMenu(event, this, 'v', false);return false;" text="04/01/2023">

I try to _SetInputValue in this input, but there are some special characters in datatype: <value="  /  /    "> it's date type, and default <text="04/01/2023">

On that web, if i put value  01012019 or 01/01/2019 still show as 01/01/2019 so i only _SetInputValue(...., '01012019')

My code:

_WD_ClearElement($sSession, "//input[@id='ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct']") 
   Sleep(300)
_WD_SetInputValue($sSession, "//input[@id='ctl00_FastBusiness_MainReport_dirExtender_form_ngay_lct']", '01012019') 
   Sleep(100)
   
Func _WD_SetInputValue($sSession, $xPath, $Value)
   $Element = _WD_WaitElement($sSession, 'xpath', $xPath, 100, 100)
   _WD_ElementAction($sSession, $Element, 'value', $Value)
EndFunc

Func _WD_ClickElement($sSession, $xPath)
   $Element = _WD_WaitElement($sSession, 'xpath', $xPath, 100, 100)
   _WD_ElementAction($sSession, $Element, 'Click')
EndFunc

Func _WD_ClearElement($sSession, $xPath)
   $Element = _WD_WaitElement($sSession, 'xpath', $xPath, 100, 100)
   _WD_ElementAction($sSession, $Element, 'Clear')
EndFunc

 

Edited by iSan
Add custom code
Link to comment
Share on other sites

@iSan If you are going to use custom functions (_WD_ClearElement, _WD_SetInputValue, etc), then you should include them in the code that you post. Also, you haven't explained the result of running your code.

Finally, some issues are more complex and are best tackled by posting a reproducer script that we can run to observe the problem. Try to find a website that exhibits the same symptoms if the actual website isn't accessible.

P.S. Your custom functions are likely calling _WD_FindElement multiple times for the same xpath, so your code is less efficient than using the UDF's functions.

Link to comment
Share on other sites

@Danp2 Sorry, i'm new in this forums and Autoit. I added my custom code Here.

I think my codes are Ok, the problem is How to SetInValue in an <input>  contains special characters in datatype: <value="  /  /    "> it's date type, and default <text="04/01/2023">

 

Link to comment
Share on other sites

Hi @iSan,

I totally agree with @Danp2, it's quite hard to follow your statements. Please do these things and we can help you:

  • Share your whole code, not just such small snippets.
  • Share either the website you try to automate or get data from. In case you can not, please share a website which is similar to your target one.
  • Share more of the DOM instead only a single tag (<input> or <span> etc.).
    • If you want to get answers about "[...] which XPath could/should I use to get this or that [...]" then it's necessary to see more of the DOM structure to suggest good XPath expressions.
  • Share your error/failure output which appears in your console.

With these actions you will get more help out of the discussions and you don't take up more of our time than necessary 🤝 .

Best regards
Sven

________________
Stay innovative!

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

@iSanThere are a few potential problems with your custom functions --

  • Lack of error checking. You should check the result of _WD_WaitElement before blindly continuing to call additional functions.
  • Your code is inefficient because it requires you to call _WD_WaitElement multiple times for the same xpath.

Also, you haven't explained the result of running your code (2nd time posting this). How are we supposed to help when we don't fully understand the problem? Do you encounter any errors? If so, what are they? Does the value of input element change? If so, to what? Etc.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...