Re: Searching for text in nested table cell



Resending.

"JWilliams" <ZZjohnZZwilliams_esq@xxxxxxxxxxxxx> wrote in message news:...

"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:%233MQZ$dKHHA.4912@xxxxxxxxxxxxxxxxxxxxxxx
JWilliams <ZZjohnZZwilliams_esq@xxxxxxxxxxxxx> wrote:
In the searchTable subroutine above the required text is matched
using:
If InStr(TD.innerText, "target cell") Then

However, because the target cell is nested, simply looking at
TD.innerText is insufficient because it can contain the text of cells
lower down the DOM hierarchy, resulting in a spurious match as shown
by the debug line beginning 4 below:

You can check TD.all.length to look for a cell that doesn't have any
child elements.
--
With best wishes,
Igor Tandetnik

Thanks Igor,

That works nicely for the simplified example I posted, however the real
target cell has the search text within a <span> </span> tag, which means
that the cell has 1 child element. Looking for a cell which has 1 child
element and contains the text results in a couple of spurious matches.

It's a pity you can't tell TD.innerText to only return text in the
immediate cell and not any nested cells.

I was hoping to look for text which is visible to the user, but think I'll
have to code something a bit more specific to the 'hidden' parts of the
HTML, e.g. there is <table> summary attribute I can use.

Thanks again for your response.



.



Relevant Pages

  • RE: insert date
    ... If ActiveCell.Column = 4 Then 'Limits macro action to column D ... If ActiveCell.Value = "" Then 'Check to see if Target cell empty ...
    (microsoft.public.excel.worksheet.functions)
  • RE: insert date
    ... Private Sub Worksheet_SelectionChange ... If ActiveCell.Value = "" Then 'Check to see if Target cell empty ...
    (microsoft.public.excel.worksheet.functions)
  • RE: insert date
    ... That's a Change-event macro that goes in a Worksheet module, ... If ActiveCell.Value = "" Then 'Check to see if Target cell empty ...
    (microsoft.public.excel.worksheet.functions)
  • RE: insert date
    ... "Larry" wrote: ... 'Automatically inserts today's date in cell in column C when selected ... 'if the cell was empty. ... If ActiveCell.Value = "" Then 'Check to see if Target cell empty ...
    (microsoft.public.excel.worksheet.functions)
  • RE: insert date
    ... "Larry" wrote: ... 'Automatically inserts today's date in cell in column C when selected ... 'if the cell was empty. ... If ActiveCell.Value = "" Then 'Check to see if Target cell empty ...
    (microsoft.public.excel.worksheet.functions)

Loading