Hi,
I think instead of iterating through the each table and then subsequently each row and cell of that table, we need a more powerful way of addressing elements using some structure specific query mechanism like XPath.
If your HTML looks something like this:
<table>
<tr>
<td>
<img src="">
<td>
</tr>
<table>
<table>
<tr>
<td>
<img src="">
<td>
</tr>
<table>
And now you want to access the <td> tag which has image with source '2.jpg', you can use the following XPath _expression_ to identify the element of interest:
"//[EMAIL PROTECTED]'2.jpg']/../"
And the Watir code to specify this will look like:
$ie.td(:xpath,"//[EMAIL PROTECTED]'2.img']/../")
We have been working on Watir to add XPath support for elements that can't (easily) be accessed using the attributes that are provided by Watir, but can be structurally addressed. A test version of that is ready which we have been testing and using internally; we plan to make it available to the larger Watir community if Bret, Paul et al think that it would be helpful. We had originally planned to do some more testing but if people might find it useful to have it available earlier we'll do it sooner.
On Fri, 19 Aug 2005 Shao Kang Tat wrote :
>I'm doing something similar. But I'm not dealing with images, rather
>links and texts, so I'd imagine the code would be similar to the one
>I"m using and would work:
>
>
>ie.tables.each do|t| # since you don't have ID's, look at every table
> for i in 1..t.row_count # for every row in this table
>
> # for every column in this row, look at its contents
> t[i].each{|c| if c.image(:src, xxx).exists? # if true, this
>is your cell
> return c.text.strip
> }
> end
>end
>
>
>
>
>
>
>
>On 8/19/05, Warren Pollans <[EMAIL PROTECTED]> wrote:
> > Hello again,
> >
> > Could some please point me to a way of finding text in a cell that
> > contains a specified image? There are no ids available for the table,
> > row or cell :-( - and there are several tables on the page. There is
> > only one cell (at a time) that contains this particular image - the
> > text in the cell is displaying status that I'm trying to capture. This
> > status msg can occur in one of four different tables - depending on
> > which form on the page is submitted - the same image is used in all
> > cases.
> >
> > I think I want to walk through the DOM looking for a td element that has
> > "img src="" - I imagine there's a simpler watir way :-)
> >
> > Thanks,
> >
> > Warren
> > _______________________________________________
> > Wtr-general mailing list
> > [email protected]
> > http://rubyforge.org/mailman/listinfo/wtr-general
> >
>
>_______________________________________________
>Wtr-general mailing list
>[email protected]
>http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
