Re: [wtr-general] Re: Trouble Locating elements using PageObject
Hey Justin, tell me what else you do not know in automation? You are awesome dude! Thanks for contributing all your knowledge to WATIR. On Wed 11 Jul, 2018, 11:43 PM Justin Ko, wrote: > The accessors do not provide a mechanism for filtering the element > collection. In other words, the exception is from > `product_line_items_in_bag_elements(:"data-product-id" => '9350486827327')`. > > You can filter the elements manually using `#find`: > > class MyPage > include PageObject > > elements(:product_line_items_in_bag, :name => /^dwfrm_cart_shipments/) # > note that you need a regex here > end > > page = MyPage.new(browser) > products = page.product_line_items_in_bag_elements > product = products.find { |e| e.data_product_id == '9351533670743' } > product.select('2') > > However, it'd be easier to skip the accessor and define a method. This > allows locating the select list directly, which can save execution time. > > class MyPage > include PageObject > > def product_element(product_id) > browser.select_list(data_product_id: product_id) > end > end > > Justin > > > On Wednesday, July 11, 2018 at 6:22:20 AM UTC-4, NaviHan wrote: >> >> Hi Justin/Titus >> >> There is a correction in the html code >> >> >> >> >> >> > id="dwfrm_cart_shipments_i0_items_i0_quantity" >> name="dwfrm_cart_shipments_i0_items_i0_quantity" >> data-product-id="9350486558733" data-item-position="1" aria-invalid="false"> >> >> >> 2 >> >> 3 >> >> 4 >> >> 5 >> >> 6 >> >> 7 >> >> 8 >> >> 9 >> >> 10 >> >> >> >> >> >> > id="dwfrm_cart_shipments_i0_items_i1_quantity" >> name="dwfrm_cart_shipments_i0_items_i1_quantity" >> data-product-id="9351533670743" data-item-position="2"> >> >> >> 2 >> >> 3 >> >> 4 >> >> 5 >> >> 6 >> >> 7 >> >> 8 >> >> 9 >> >> 10 >> >> >> >> >> >> > id="dwfrm_cart_shipments_i0_items_i2_quantity" >> name="dwfrm_cart_shipments_i0_items_i2_quantity" >> data-product-id="9351533671290" data-item-position="3" aria-invalid="false"> >> >> >> 2 >> >> 3 >> >> 4 >> >> 5 >> >> 6 >> >> 7 >> >> 8 >> >> 9 >> >> 10 >> >> >> >> 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... >>> >>> >>> 9830318220466018 >>> >>> >>> >> data-gift-id="9830318220466018"> >>> >>> Remove >>> >>> >>> >>> >>> >>> >>> 9831228610400260 >>> >>> >>> >> data-gift-id="9831228610400260"> >>> >>> Remove >>> >>> >>> >>> >>> >>> >>> 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. > -- -- 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: Trouble Locating elements using PageObject
The accessors do not provide a mechanism for filtering the element collection. In other words, the exception is from `product_line_items_in_bag_elements(:"data-product-id" => '9350486827327')`. You can filter the elements manually using `#find`: class MyPage include PageObject elements(:product_line_items_in_bag, :name => /^dwfrm_cart_shipments/) # note that you need a regex here end page = MyPage.new(browser) products = page.product_line_items_in_bag_elements product = products.find { |e| e.data_product_id == '9351533670743' } product.select('2') However, it'd be easier to skip the accessor and define a method. This allows locating the select list directly, which can save execution time. class MyPage include PageObject def product_element(product_id) browser.select_list(data_product_id: product_id) end end Justin On Wednesday, July 11, 2018 at 6:22:20 AM UTC-4, NaviHan wrote: > > Hi Justin/Titus > > There is a correction in the html code > > > > > > id="dwfrm_cart_shipments_i0_items_i0_quantity" > name="dwfrm_cart_shipments_i0_items_i0_quantity" > data-product-id="9350486558733" data-item-position="1" aria-invalid="false"> > > > 2 > > 3 > > 4 > > 5 > > 6 > > 7 > > 8 > > 9 > > 10 > > > > > > id="dwfrm_cart_shipments_i0_items_i1_quantity" > name="dwfrm_cart_shipments_i0_items_i1_quantity" > data-product-id="9351533670743" data-item-position="2"> > > > 2 > > 3 > > 4 > > 5 > > 6 > > 7 > > 8 > > 9 > > 10 > > > > > > id="dwfrm_cart_shipments_i0_items_i2_quantity" > name="dwfrm_cart_shipments_i0_items_i2_quantity" > data-product-id="9351533671290" data-item-position="3" aria-invalid="false"> > > > 2 > > 3 > > 4 > > 5 > > 6 > > 7 > > 8 > > 9 > > 10 > > > > 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... >> >> >> 9830318220466018 >> >> >> > data-gift-id="9830318220466018"> >> >> Remove >> >> >> >> >> >> >> 9831228610400260 >> >> >> > data-gift-id="9831228610400260"> >> >> Remove >> >> >> >> >> >> >> 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.
[wtr-general] Re: Trouble Locating elements using PageObject
Hi Justin/Titus There is a correction in the html code 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 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... > > > 9830318220466018 > > > data-gift-id="9830318220466018"> > > Remove > > > > > > > 9831228610400260 > > > data-gift-id="9831228610400260"> > > Remove > > > > > > > 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.
[wtr-general] Re: Trouble Locating elements using PageObject
I tried this way. but got error ArgumentError: wrong number of arguments (given 1, expected 0) elements(:product_line_items_in_bag, :name => 'dwfrm_cart_shipments') product_line_items_in_bag_elements(:"data-product-id" => '9350486827327').set(2) 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... > > > 9830318220466018 > > > data-gift-id="9830318220466018"> > > Remove > > > > > > > 9831228610400260 > > > data-gift-id="9831228610400260"> > > Remove > > > > > > > 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.
[wtr-general] Re: Trouble Locating elements using PageObject
Hi Justin/Titus Facing another challenge here. I have a section of a page with multiple outer div which has lots of inner divs/spans etc of which Im interested in a select with an attribute named "data-product-id" which has a specific value. 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 My requirement is to find the select element with a particular value of "data-product-id" attribute and set it to say 2 Any clue on how to achieve this? On Wednesday, 11 July 2018 13:48:56 UTC+10, NaviHan wrote: > > Hi Justin > > That worked like a charm. PageObject gem is amazing :-) > > 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... >> >> >> 9830318220466018 >> >> >> > data-gift-id="9830318220466018"> >> >> Remove >> >> >> >> >> >> >> 9831228610400260 >> >> >> > data-gift-id="9831228610400260"> >> >> Remove >> >> >> >> >> >> >> 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.