I guess my gut would tell me to add specific locators for the elements to
make them easier to manage.

my first question would be " why does the index matter? " once you have the
element?
what are you actually trying to validate?

the code examples seem ok. but if its a row of data it would make more
sense to fix the markup for each row of things since there is no actual
markup ill try my hand.
lets say its gross and looks like this for a row:

<div class="grid">
>   <a href=''>View</a>
>   <a href=''>Edit</a>
>   <a href=''>Make Default</a>
>   <a href=''>Delete</a>
>   <p>text3</p>
> </div>


wouldn't without caring about the index it be easier to do:


> browser.div(text: 'text3').parent.link(text: 'Delete').click


then even

def some_row(row_text)
>   browser.div(text: row_text)
> end
> def some_row_perform(row_text, action)
>     some_row(row_text).parent.link(text: action)
> end


this would let me do whatever I want with the element

> some_row_perform('text3', 'Delete').html
> some_row_perform('text3', 'Delete').present?
> some_row_perform('text3', 'Delete').visible?
> some_row_perform('text3', 'Delete').click


In Taza (https://github.com/hammernight/taza)
for my page class I would just do something similar

>
> element(:some_row) { |row_text| browser.div(text: row_text) }
> element(:do_something_to_row) { |row_text, action|
> some_row(row_text).parent.link(text: action) }


pretty much the same

some_row_perform('text3', 'Delete').html
> some_row_perform('text3', 'Delete').present?
> some_row_perform('text3', 'Delete').visible?
> some_row_perform('text3', 'Delete').click






On Wed, Jul 20, 2016 at 1:04 PM, Titus Fortner <[email protected]>
wrote:

> I especially like it as a way to abstract it out for multiple operations.
> So: Edit Button / Delete Button / Make Default / View Details, etc, etc can
> all use it.
> If it was one operation, I'd be likely to make similar use of the parent
> method as you described.
>
>
> On Wednesday, July 20, 2016 at 11:43:19 AM UTC-5, Chuck van der Linden
> wrote:
>>
>> On Tuesday, July 19, 2016 at 6:44:36 PM UTC-7, Titus Fortner wrote:
>>>
>>> The pattern that I'm assuming Soori is asking about is one I often use
>>> for lists. Say I have a list of addresses and I want to delete one.
>>>
>>> I'll do something like this:
>>>
>>> def delete_address(address)
>>>   index = browser.div(id: "address_section").divs(class:
>>> "address_item").find_index do |div|
>>>     address == construct_address(div)
>>>   end
>>>   browser.div(id: "address_section").button(text: "Delete", index:
>>> index).click
>>> end
>>>
>>> (where construct address builds an object from what is on the page in a
>>> way that can be compared to the parameter we have)
>>>
>>>
>>> ah yeah I've had to deal with similar.. usually it depends on the HTML
>> structure what I do.  Often it's just as easy to find the table-row, or
>> container with the identifier, and use .parent.button(text:
>> "Delete").click.  When that's the case I usually find I like that better.
>>  but sometimes the structure doesn't allow for easy use of parent or
>> containers because the items and the associated delete button/link don't
>> share a common container.. so yeah in that case the index trick is a good
>> way to go.
>>
> --
> --
> Before posting, please read http://watir.com/support. In short: search
> before you ask, be nice.
>
> [email protected]
> http://groups.google.com/group/watir-general
> [email protected]
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Watir General" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to