Discussion:
[wtr-general] Maybe look in an iframe? error when clicking button
NaviHan
2018-09-20 10:50:21 UTC
Permalink
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">


<h5 class="applied-promo-codes-title">Applied codes:</h5>

<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>


<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>

</div>



There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them

I have the page object defined as and the step def and method as follows

buttons(:delete_coupon, :id => 'delete-coupon')




And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end


def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end


The script removes the coupon "9840150120702065", but when trying to remove
the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block in
remove_voucher_from_bag'



Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Ko
2018-09-20 13:15:31 UTC
Permalink
Hi Navi,

How is #delete_coupon_elements defined? I would have expected it to
re-determine the collection each time it was called.

Titus made some fixes around collections in 6.13 and 6.14. You could see if
that resolves your issue.

I suppose it could be a timing issue - eg :
1. The first coupon button is clicked (but not immediately removed from the
UI due to asychronous code)
2. The coupon collection is re-calculated (still 2 since the first is still
not deleted)
3. The first coupon actually gets removed
4. The locating of the second button is no longer possible.

Alternatively, there isn't a benefit of iterating over the collection of
coupons. Technically, it's slower. You could locate and delete the specific
coupon:

def remove_voucher_from_bag coupon_id
browser.button(id: 'delete-coupon', value: coupon_id).click
end

Justin
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
NaviHan
2018-09-20 13:30:17 UTC
Permalink
Hi Justin

The button collection is defined as

buttons(:delete_coupon, :id => 'delete-coupon')
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Ko
2018-09-20 13:57:42 UTC
Permalink
Sounds like the timing issue. Maybe try waiting for the coupon to be
removed before continuing:

delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.tap(&:
click).wait_while(&:present?)

Justin
Post by NaviHan
Hi Justin
The button collection is defined as
buttons(:delete_coupon, :id => 'delete-coupon')
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
NaviHan
2018-09-20 14:04:02 UTC
Permalink
Sure Justin, Let me try that

But what does tap(&:click)do?
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Titus Fortner
2018-09-20 14:43:30 UTC
Permalink
The tap methods returns self after doing whatever is in the block. It lets you chain methods more easily.
--
--
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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
NaviHan
2018-09-20 14:47:35 UTC
Permalink
Ok, Titus, but why use click on self?
Just searched the web for documentation on tap, couldnt find it.

Could you please point me to if any?
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Titus Fortner
2018-09-20 15:24:15 UTC
Permalink
Ah, yes, it's a Ruby object method and has nothing to do with tapping a
screen or the like:
https://ruby-doc.org/core-2.5.1/Object.html#method-i-tap

foo.click
==> nil

foo.tap(&:click}
==> foo

For example:

def foo
result = do_something
puts "We did something"
result
end

can be written on one line:

def foo
do_something.tap { puts "We did something" }
end
Post by NaviHan
Ok, Titus, but why use click on self?
Just searched the web for documentation on tap, couldnt find it.
Could you please point me to if any?
Post by NaviHan
I have a bag page where I have applied two coupons. Once the coupons are
applied the source looks like this
<div class="small-12 all-applied-coupons column promo-codes-list">
<h5 class="applied-promo-codes-title">Applied codes:</h5>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
9840150120702065
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="9840150120702065" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
<div class="row promo-code-row">
<div class="small-8 large-6 xxlarge-8 column small-text-left
promo-code-column">
<span class="promo-code-item">
autotest_order
</span>
</div>
<div class="column small-text-right">
<button type="button" class="pointer" value="autotest_order" id=
"delete-coupon">
<span class="icon icon-cross-standard-small-black"></span>
<span class="underline align-text remove-promo-code">Remove</span>
</button>
</div>
</div>
</div>
There is a remove link(button) against each coupon. Basically my test
clicks these buttons to remove them
I have the page object defined as and the step def and method as follows
buttons(:delete_coupon, :id => 'delete-coupon')
And(/^the customer removes the coupons\/vouchers from Bag Page$/) do |
table|
on(MybagPage) do |page|
@remove_voucher_list = table.hashes
@remove_voucher_list.each {|data|
page.remove_voucher_from_bag data['voucher_id']
}
end
def remove_voucher_from_bag coupon_id
delete_coupon_elements.find{|el| el.value.to_s == coupon_id.to_s}.click
end
The script removes the coupon "9840150120702065", but when trying to
remove the next coupon fails with folowing message
Watir::Exception::UnknownObjectException: timed out after 30 seconds,
waiting for #<Watir::Button: located: false; {:id=>"delete-coupon",
:tag_name=>"button", :index=>1}> to be located; Maybe look in an iframe?
./features/support/pages/Frontend/Cotton_On/Mybag_Page.rb:141:in `block
in remove_voucher_from_bag'
Any clue whats missing 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-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
NaviHan
2018-09-21 07:19:34 UTC
Permalink
Hi Justin and Titus

tap(&:click) did the trick

Now its successfully removing the second voucher as well

Thanks for the detailed explanation..

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