RohanM Posted February 28, 2023 Posted February 28, 2023 How to loop trough html table TR and TD elements after find table by using _WD_FindElement() I in progress of migrating my IE browser to Edge browser by using WebDriver UDF, below is my old code that I am getting the html table and looping through all TR and TD element to check the inner html data to identity cell values to choose particular row. but in the UDF if I get the correct table html code its not allowing me to loop through elements, can anyone help me on this? New code with UDF Local $sElement = _WD_FindElement($Session, $_WD_LOCATOR_ByXPath,"//table[(@cellpadding='3') and (@cellspacing='0') and (@width='100%') and (@border='0')]") Local $sHTML = _WD_ElementAction($Session, $sElement, 'property', 'innerHTML') old code IE _IEAction($oLink, 'click') _IELoadWait($oIE) While 1 Sleep(2000) Local $oTables = Null, $iTable = Null Local $oTables = _IETableGetCollection($oIE) For $iTable In $oTables Local $oTableData = _IETableWriteToArray($iTable, True) If UBound($oTableData, 2) > 4 Then ;And UBound($oTableData) > 1 If StringInStr($oTableData[0][0], 'ID', 2) > 0 And StringInStr($oTableData[0][6], 'History ', 2) > 0 Then _ArrayDisplay($oTableData, '$oTableData', Default, 😎 ;### Debug Array ExitLoop 2 EndIf EndIf Next WEnd Local $oTrs = $iTable.rows Local $iRows = $oTrs.length Local $DocType = False, $iLink = False For $oTr In $oTrs $oTds = $oTr.cells $iCol = 0 For $oTd In $oTds $sdf = String($oTd.innerText) If StringInStr($sdf, 'Financial Invoice') > 0 Then $DocType = True EndIf If $DocType Then If StringInStr($sdf, 'View') > 0 Then $oTd.innerHtml Local $aArray = StringRegExp($oTd.innerHtml, '(?m)"(.*?)"', 2) $iLink = True ExitLoop 2 EndIf EndIf Next Next $DocUrl = 'https://network.infornexus.com' & StringReplace($aArray[1], 'amp;', '') _IENavigate($oIE, $DocUrl, 1) _IELoadWait($oIE)
Danp2 Posted February 28, 2023 Posted February 28, 2023 Have you checked out _WD_GetTable? Not sure if you can use it for the current task, but it should serve as a model on how to retrieve the desired elements. Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted March 1, 2023 Author Posted March 1, 2023 Hi @Danp2 thanks for your reply. _WD_GetTable function also will return only innerHTML of the table it will not return table as a object to iterate through. what I need here is: in this table there are multiple hrefs I want to click one of the link by checking table cell value Local $oTrs = $iTable.rows Local $iRows = $oTrs.length Local $DocType = False, $iLink = False For $oTr In $oTrs $oTds = $oTr.cells $iCol = 0 For $oTd In $oTds $sdf = String($oTd.innerText) If StringInStr($sdf, 'Financial Invoice') > 0 Then $DocType = True EndIf If $DocType Then If StringInStr($sdf, 'View') > 0 Then $oTd.innerHtml Local $aArray = StringRegExp($oTd.innerHtml, '(?m)"(.*?)"', 2) $iLink = True ExitLoop 2 EndIf EndIf Next Next $DocUrl = 'https://network.infornexus.com' & StringReplace($aArray[1], 'amp;', '') _IENavigate($oIE, $DocUrl, 1) _IELoadWait($oIE)
Danp2 Posted March 1, 2023 Posted March 1, 2023 @RohanMThese are the two options that I can suggest that you investigate -- Option 1 _WD_GetTable already contains the coding to traverse the table's rows and column, so you could analyze this code and use it as a guide to implement your own custom routine. Option 2 Use _WD_GetTable to obtain an array. Search this array to determine the row/column combination that meets your criteria. Build a custom xpath using the row/col info that allows you to retrieve the target cell Retrieve the target element Click it or perform further actions as needed Latest Webdriver UDF Release Webdriver Wiki FAQs
RohanM Posted March 1, 2023 Author Posted March 1, 2023 Hi @Danp2 thanks for your suggestions, let me check this out.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now