[Celerity-users] Magic transmogrifying row object
Ben Butler-Cole
ben at bridesmere.com
Wed Nov 25 11:59:56 EST 2009
2009/11/25 Jari Bakken <jari.bakken at gmail.com>:
>
>> I need to get at the underlying HtmlUnit object for a table row. When
>> I first tried it I discovered that it didn't have the methods I was
>> expecting. By trial and error I have discovered that the first time I
>> access the row's HtmlUnit object (via the .object method) it returns a
>> List. The second time it returns an HtmlTableRow. Ummm????
>
> Without having the code in front of me, I would guess this is caused by the
> lazy locating of elements. If you try row(...).locate you should get the
> correct HU object directly.
Calling .locate *always* gives the wrong type (the list instead of the
HtmlTableRow).
I have put the code in front of myself and had a look. I think there
is a bug in Celerity::TableRow.locate. The relevant bits look like
this:
module Celerity
class Element
def locate
@object = ElementLocator.new(@container,
self.class).find_by_conditions(@conditions)
end
def object
@object || locate
end
end
class TableRow < Element
def locate
super
@cells = @object.getCells if @object
end
end
end
So the .object method in Element expects .locate to return the object
as well as assign it. But TableRow's overridden .locate returns the
cells instead. The easiest fix is:
module Celerity
class TableRow
def locate
super
@cells = @object.getCells if @object
@object
end
end
end
Which I have verified locally.
> Out of interest, why do you need the underlying object?
I want to call the mouse* methods. I've added this:
class Celerity::Element
def mouse_down
object.mouseDown
end
def mouse_up
object.mouseUp
end
def mouse_move
object.mouseMove
end
end
Ben
More information about the Celerity-users
mailing list