So, it looks like there are a couple things going on here.
> wait_until with present flag will wait until the element is present and then
> clicks it
I think you just misspoke here, but to clarify just in case, `#click`
method will automatically wait for the element it is clicking to be
present based on that element's locator. `#wait_until(&:present?)`
does not automatically click anything
Figuring out if something is "displayed" is very tricky and the
drivers do their best job to approximate it. JavaScript will flummox
them for sure. Is the JavaScript jquery? You can wait for the jquery
queue to be zero. That would be easiest. I think PO gem even has a way
to do that automatically for you. Or you can: `browser.wait_until {
execute_script("return jQuery.active == 0") }`
If it isn't javascript, then it gets difficult because figuring out
these transitionary stages involves a race condition both before and
after the transition. I'm actually curious how other people handle
these with their explicit waits. I petitioned (and it was agreed to)
for the next version of the w3c specification to require an endpoint
to allow us to implement an `#interactible?` method, which we could
then poll for as an explicit wait. In the meantime, I think the best
answer looks like this, but it's a little hacky
def ensure_click(element)
element.click
rescue Selenium::WebDriver::Error::UnknownError => ex
raise unless ex.message.include?("is not clickable")
sleep 0.1
retry
end
As for `StaleElementReferenceError`, update to Watir 6.12. I think we
fixed a bug that caused that to slip through. If you are still seeing
that with 6.12, it's a problem and I'll want to dig into it more. You
should never get that with Watir.
On Mon, Aug 6, 2018 at 8:52 PM NaviHan <[email protected]> wrote:
>
> You are right. It works with pure Watir.
> Unfortunately my company insists Pageobejct :-)
>
> With a fresh mind wait_while and wait_until is so confusing
> For instance wait_until with present flag will wait until the element is
> present and then clicks it and I clearly do not understand why its should
> click some other element in this case "loader.bg"
>
> May be I should wait for Justin Ko to help me with this as I use page object.
>
> I slightly modified the code as
>
> variation_groups_elements.find { |el|
> el.wait_until(&:present?).title.include? color }.click
>
> This works when it clicks on the first color say "eucalyptus". After that the
> script does a couple of things and then go to select a different color say
> black.
> Thats when this is failing.
>
> Selenium::WebDriver::Error::UnknownError: unknown error: Element <a
> class="swatchanchor"
> href="https://ci.cottonon.com/AU/show-variation/?dwvar_2003013_color=2003013-05&pid=2003013&dwvar_2003013_size=XXS&originalPid=2003013-05"
> title="Select Colour: BLACK" data-attribute-type="color">...</a> is not
> clickable at point (504, 64). Other element would receive the click: <div
> class="loader-bg"></div>
> (Session info: chrome=68.0.3440.84)
> (Driver info: chromedriver=2.41.578737
> (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1
> x86_64)
>
> The cucumber script is
>
> And the user navigates to PDP of the product "123"
> And the user selects the color "eucalyptus"
> And the user selects the online size "XXS"
> And the user navigates to In-Store tab
> And the user searches for stock in stores by postcode 3030
> And the user selects the color "black"
>
> There is a javascript spinner which appears while loading the list of stores
> for line "And the user searches for stock in stores by postcode 3030"
>
>
> But as we are using wait_until(&:present) I would expect the script to wait
> till the next color is present and then do the click.
>
> Any more thoughts?
> Selenium::WebDriver::Error::StaleElementReferenceError: stale element
> reference: element is not attached to the page document
> (Session info: chrome=68.0.3440.84)
> (Driver info: chromedriver=2.36.540470
> (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1
> x86_64)
>
>
> On Friday, 3 August 2018 15:12:45 UTC+10, NaviHan wrote:
>>
>> I have a functionality where I click an a link from an email a voucher gets
>> added to the shopping cart and a pop up appears with a message. Im trying to
>> assert the text in the popup
>> I have defined the element as
>>
>> div(:cta_description, :css => '.homepage-clicktoactiavte-description')
>>
>> Tried to use a mix of Watir and Pageobejct to read the text. The below code
>> works 5 out of 10 times.
>>
>> @rewards_popup_txt = Watir::Wait.until{cta_description_element}.text
>> @rewards_popup_txt = @rewards_popup_txt.gsub(/[^$,.A-Za-z0-9]/," ")
>> return @rewards_popup_txt
>>
>>
>> Tried using, which doesnt even set the @reward_popup_txt and shows error
>>
>>
>> if (Watir::Wait.while {cta_description_element.visible?})
>> @rewards_popup_txt = cta_description_element.text
>> end
>> @rewards_popup_txt = @rewards_popup_txt.gsub(/[^$,.A-Za-z0-9]/," ")
>> return @rewards_popup_txt
>>
>> Error
>> NoMethodError: undefined method `gsub' for nil:NilClass
>> ./features/support/pages/Frontend/Cotton_On/Loyalty_Page.rb:22:in
>> `rewards_popup_description'
>>
>> Any stable way to do the job?
>
> --
> --
> 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.
>
> [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
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.