Yeah, wow, your code is kind of all over the place. What are you actually 
trying to do?

Notes:
1. Don't use multiple classes as a string value in a class locator
2. innerText isn't an attribute
3. did you include PageObject module?
4. Did you define `nav_divs`?
5. Using `Watir::Wait` directly is not recommended
6. Ugh, PO gem makes all of this so much harder than it needs to be



On Tuesday, July 3, 2018 at 10:14:13 AM UTC-5, NaviHan wrote:
>
> Hi Titus
>
> Tried this
>
> Enter code here...divs(:nav_divs, class: "row applied-voucers-list")
>
> and
>
> Enter code here...@voucher_val = Watir::Wait.until {nav_divs_element[index
> ].span_element}.attribute_value("innerText")
>
> index = 0 as passed by the caller
>
> However Im getting the error
> Enter code here...NoMethodError: undefined method `nav_divs_element' for 
> #<Watir::Browser:0x0000000005b407f8>
>
>
> Any clue?
>
> On Tuesday, 3 July 2018 23:56:26 UTC+10, Titus Fortner wrote:
>>
>> Yes, how Page Object provides for the ability to manage dynamic 
>> references is one of my major frustrations with the gem's API.
>>
>> Firstly, Watir (and Page Object) allow you to pass in multiple parameters 
>> in a hash format:
>> div(:nav_div, {class: 'applied-vouchers-list', index: 1})
>> nav_div_element
>>
>> This can also be done with less hard coding using collections:
>> divs(:nav_divs, {class: 'applied-vouchers-list')
>> nav_divs_element[1]
>>
>> Note that you can't put multiple classes (space separated values) into 
>> the class locator, without using an array.
>>
>> What it appears you actually want is to find if a specific value is 
>> present, though, which is poorly suited for hard coding an element in the 
>> PO gem. So I'd recommend creating a separate method for it:
>>
>> def code_removable?(id)
>>   button_element(data_gift_id: id)
>>   el.exists? && el.parent.text == 'Remove'
>> end
>>
>>
>>
>>
>>
>> On Tuesday, July 3, 2018 at 7:06:15 AM UTC-5, NaviHan wrote:
>>>
>>> Hi All
>>>
>>> In fact I nailed it in parts by using
>>>
>>>   div(:nav_div, class: "row applied-voucers-list")
>>>   span (:applied_voucher) do |page|
>>>     page.nav_div_element.span_element
>>>   end
>>>
>>>
>>> This gives me the first div.
>>>
>>> But how do I access the second div using index parameter?
>>>
>>> On Tuesday, 3 July 2018 21:48:19 UTC+10, NaviHan wrote:
>>>>
>>>> This is my first post here. Apologies if there is a mistake.
>>>>
>>>> I have a section of a page as attached in the pic.
>>>>
>>>>
>>>> The html code for the section is as follows
>>>> Enter code here...<div class="small-12 applied-evouchers">
>>>> <div class="row applied-voucers-list">
>>>> <div class="small-6">
>>>> <span>9830318220466018</span>
>>>> </div>
>>>> <div class="small-6 small-text-right"> 
>>>> <button type="button" class="remove-gift-cert" 
>>>> data-gift-id="9830318220466018">
>>>> <span class="icon icon-cross-standard-small-black"></span>
>>>> <span class="underline remove-evoucher-button-text">Remove</span>
>>>> </button>
>>>> </div>
>>>> </div>
>>>> <hr>
>>>> <div class="row applied-voucers-list">
>>>> <div class="small-6">
>>>> <span>9831228610400260</span>
>>>> </div>
>>>> <div class="small-6 small-text-right"> 
>>>> <button type="button" class="remove-gift-cert" 
>>>> data-gift-id="9831228610400260">
>>>> <span class="icon icon-cross-standard-small-black"></span>
>>>> <span class="underline remove-evoucher-button-text">Remove</span>
>>>> </button>
>>>> </div>
>>>> </div>
>>>> <hr>
>>>> </div>
>>>>
>>>> I need to assert two value here
>>>>
>>>> 1. The vouchers applied, which are 9830318220466018 & 9831228610400260
>>>> 2. The span "Remove"
>>>>
>>>> The issue Im facing is as these two divs are identical and 1 & 2 doesnt 
>>>> have a unique identifier I cannt locate them using PageObjects.
>>>>
>>>> I can locate the element using the following Java script
>>>> document.getElementsByClassName('applied-voucers-list')[0].innerText;
>>>> This returns 
>>>> Enter code here..."9830318220466018
>>>> Remove
>>>> "
>>>>
>>>> I tried to capture this with the code
>>>> Enter code here...@var = 
>>>> @browser.execute_script("document.getElementsByClassName('applied-voucers-list')[0].innerText;")
>>>>
>>>> This isnt working
>>>>
>>>> Any clue?
>>>>
>>>>

-- 
-- 
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.

Reply via email to