[wtr-general] Re: Issue with watir index or Am I doing something wrong

2018-11-23 Thread NaviHan
Hi Justin

The collection was the first thing I tried. But the issue is when there is 
only one gift card applied, meaning only one div with class 
> Having trouble using index.
>
> I have a section of a page as below.
> 
> 
> Card
> Amount Taken
> 
>  ="display: flex;">
> ...163867647149
> $20.00
> 
>  data-gcid="2790030163867647149">
> 
> 
> 
> 
> 
>  style="display: flex;">
> ...169169063156
> $25.90
> 
> ($74.10 left on card)
> 
> 
> 
>  data-gcid="2790030169169063156">
>  >
> 
> 
> 
> 
> 
>
>
> The pageobject is defined as
>
> div(:applied_gift_cards, :class => 'gc-list')
>
>
>
>
> And Im trying to access "...163867647149 " and "$20.00" as which gave 
> error
>
> return applied_gift_cards_element.div_element(:index => 1).div_element(:index 
> =>0).text
>
> return applied_gift_cards_element.div_element(:index => 1).div_element(:index 
> =>0).text
>
> Watir::Exception::UnknownObjectException: timed out after 30 seconds, 
> waiting for #"gc-list", 
> :tag_name=>"div"} --> {:index=>1, :tag_name=>"div"} --> {:index=>0, 
> :tag_name=>"div"}> to be located
>
> When printing the same element actually prints the Pageobect
> puts applied_gift_cards_element.div_element(:index => 1).div_element(:index 
> =>0)
> #
>
>
> A puts of the following printed as below which is again confusing
>
> puts applied_gift_cards_element.div_element(:index => 0).inner_html
> puts applied_gift_cards_element.div_element(:index => 1).inner_html
> puts applied_gift_cards_element.div_element(:index => 2).inner_html
> puts applied_gift_cards_element.div_element(:index => 3).inner_html
>
> Card
>  Amount Taken
> Card
> Amount Taken
> ...163867647149$20.00 type="button" class="remove-gift-cert pointer" 
> data-gcid="2790030163867647149">
>
>
>
>
> Am I doing something wrong here?
>
>

-- 
-- 
Before posting, please read 
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
 
In short: search before you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com
--- 
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 watir-general+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[wtr-general] Re: Issue with watir index or Am I doing something wrong

2018-11-23 Thread Justin Ko
Instead of working from the the "gc-list", you could work from the 
"gift-cards-list". It would save a level of nesting and eliminate the child 
vs descendant difference:

# Page-Object
divs(:applied_gift_card, :class => 'gift-cards-list')

# Usage
p page.applied_gift_card_elements[0].div_element(index: 0).text
#=> "...163867647149"
p page.applied_gift_card_elements[0].div_element(index: 1).text
#=> "$20.00"

For readability, I would suggest taking it a step further and using page 
sections:

class MyPage
  include PageObject

  class AppliedGiftCard
include PageObject

div(:card, index: 0)
div(:amount_taken, index: 1)
  end

  page_sections(:applied_gift_cards, AppliedGiftCard, class: 
'gift-cards-list', tag_name: 'div')
end

page = MyPage.new(browser)
p page.applied_gift_cards[0].card
#=> "...163867647149"
p page.applied_gift_cards[0].amount_taken
#=> "$20.00"
p page.applied_gift_cards[1].card
#=> "...169169063156"
p page.applied_gift_cards[1].amount_taken
#=> "$25.90\n($74.10 left on card)"

Justin


On Thursday, November 22, 2018 at 11:44:34 PM UTC-5, NaviHan wrote:
>
> Oops my understanding was wrong here :-(
>
> I can achieve this by using 
>
> return applied_gift_cards_element.children[index.to_i].children[0].text
>
> Is there a a better way?
>
>
> On Friday, 23 November 2018 13:06:07 UTC+11, NaviHan wrote:
>>
>> Having trouble using index.
>>
>> I have a section of a page as below.
>> 
>> 
>> Card
>> Amount Taken
>> 
>> > style="display: flex;">
>> ...163867647149
>> $20.00
>> 
>> > data-gcid="2790030163867647149">
>> > >
>> 
>> 
>> 
>> 
>> > style="display: flex;">
>> ...169169063156
>> $25.90
>> 
>> ($74.10 left on card)
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>
>>
>> The pageobject is defined as
>>
>> div(:applied_gift_cards, :class => 'gc-list')
>>
>>
>>
>>
>> And Im trying to access "...163867647149 " and "$20.00" as which gave 
>> error
>>
>> return applied_gift_cards_element.div_element(:index => 
>> 1).div_element(:index =>0).text
>>
>> return applied_gift_cards_element.div_element(:index => 
>> 1).div_element(:index =>0).text
>>
>> Watir::Exception::UnknownObjectException: timed out after 30 seconds, 
>> waiting for #"gc-list", 
>> :tag_name=>"div"} --> {:index=>1, :tag_name=>"div"} --> {:index=>0, 
>> :tag_name=>"div"}> to be located
>>
>> When printing the same element actually prints the Pageobect
>> puts applied_gift_cards_element.div_element(:index => 1).div_element(:index 
>> =>0)
>> #
>>
>>
>> A puts of the following printed as below which is again confusing
>>
>> puts applied_gift_cards_element.div_element(:index => 0).inner_html
>> puts applied_gift_cards_element.div_element(:index => 1).inner_html
>> puts applied_gift_cards_element.div_element(:index => 2).inner_html
>> puts applied_gift_cards_element.div_element(:index => 3).inner_html
>>
>> Card
>>  Amount Taken
>> Card
>> Amount Taken
>> ...163867647149$20.00> type="button" class="remove-gift-cert pointer" 
>> data-gcid="2790030163867647149">
>>
>>
>>
>>
>> Am I doing something wrong here?
>>
>>

-- 
-- 
Before posting, please read 
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
 
In short: search before you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com
--- 
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 watir-general+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.