CaptainBeardsEyesBeard Posted September 8, 2020 Posted September 8, 2020 What table looks like What html looks like So I use a for loop to search this table for "Not Allocated" $colLinks = _IEGetObjById($oIE, "ctl00_MPH_PanelListing_ctlInvoiceListing") $TDs = _IETagNameGetCollection($colLinks, "td") For $oLink in $TDs If String($oLink.textContent) = "Not Allocated" Then ConsoleWrite(@CRLF & "Found Not Allocated ") _IEAction($oLink, "click") ExitLoop EndIf Next However I would then like to be able to access the adjacent TD cells. (such as the Customer Name/ Ledger Reference/Matter Number etc. How would I do this whilst ensuring I'm not pulling a TD cell from a difference row?
CaptainBeardsEyesBeard Posted September 8, 2020 Author Posted September 8, 2020 So my plan was to loop through the table collections and then search using string in string _IETableGetCollection($oIE) $iNumTables = @extended For $i = 0 To $iNumTables - 1 $oTable = _IETableGetCollection($oIE, $i) $aTableData = _IETableWriteToArray($oTable) if StringInStr($aTableData[0][0], "Not Allocated") Then MsgBox(64, "Debug", "Found the table with Not Allocated in", 2) $aTableData[0][0] = $NotAllocatedTableCell _ArrayDisplay($aTableData, "Table #" & $i) MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $NotAllocatedTableCell) MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $aTableData[0][0]) endif Next However as some tables seem to contain nothing it then fails with (239) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: So I'm wondering if there is a way to test that $aTableData[0][0] is a valid array?
Dan_555 Posted September 8, 2020 Posted September 8, 2020 You can use the Ubound command, to check how many items are in the array. You can use IsArray to determine if the variable is an array. And whenever you call the functions, which return an array, you can check if @error has been set or not. Some of my script sourcecode
Danp2 Posted September 8, 2020 Posted September 8, 2020 Once you've found an element, you can use it as the basis to find it's parent, siblings, children, etc. Lots of examples on the forum and the web. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted September 8, 2020 Author Posted September 8, 2020 Does anyone know why I get Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Despite using the Isarray function and wrapping in an if statement? _IETableGetCollection($oIE) $iNumTables = @extended For $i = 0 To $iNumTables - 1 $oTable = _IETableGetCollection($oIE, $i) $aTableData = _IETableWriteToArray($oTable) If IsArray($aTableData) Then if StringInStr($aTableData, "Not Allocated") Then If @Error then ConsoleWrite(@CRLF & "@Error triggered: $aTableData is not an array.") EndIf MsgBox(64, "Debug", "Found the table with Not Allocated in", 2) $aTableData[0][0] = $NotAllocatedTableCell MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $NotAllocatedTableCell) MsgBox(64, "Debug", "$NotAllocatedTableCell equals: " & $aTableData[0][0]) endif EndIf Next
Danp2 Posted September 8, 2020 Posted September 8, 2020 I don't think you can pass an array as the first parameter to StringInStr. You should use _ArraySearch instead. Latest Webdriver UDF Release Webdriver Wiki FAQs
CaptainBeardsEyesBeard Posted September 8, 2020 Author Posted September 8, 2020 You should be able to do if StringInStr($aTableData[0][0], "Not Allocated") Then though?
Danp2 Posted September 8, 2020 Posted September 8, 2020 Yes, you can perform a string search on a single array element. However, that's not what you were doing in the posted code. Latest Webdriver UDF Release Webdriver Wiki FAQs
Dan_555 Posted September 8, 2020 Posted September 8, 2020 (edited) When i'm prototyping my scripts, i usually use _ArrayDisplay to see what the array is containing. $oTable = _IETableGetCollection($oIE, $i) _ArrayDisplay($oTable) $aTableData = _IETableWriteToArray($oTable) _ArrayDisplay($aTableData) You may notice, that, if one array contain nothing, for e.g $aTableData[0][0] will be set to 0 The other way, which i found useful, is to check if $aTableData is -1 Here is an example: #include <Misc.au3> Dim $aFont[8] ;Font array definition $aFont = _ChooseFont($aFont[2], $aFont[3], $aFont[5], $aFont[4], 0, 0, 0) ConsoleWrite($aFont & @CRLF) if $aFont=-1 then ConsoleWrite ("not an array" & @crlf) EndIf If you choose a valid Font, then -1 and "not an array" will not appear in the console. But if you click on cancel, then you will see both messages. Edited September 8, 2020 by Dan_555 Some of my script sourcecode
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