The html source is 
<ul class="swatches color open row small-up-6 medium-up-6 xxlarge-up-7 
columns">
        
            
                <li class="selectable selected column">
                    
                        <a class="swatchanchor" href=
"https://xxx.com/AU/show-variation/?pid=2003013&amp;originalPid=2003013-05"; 
title="Select Colour: BLACK" data-attribute-type="color">
                            
                                <img src=
"/on/demandware.static/Sites-Site/-/default/dw0ba6a777/images/noImgLarge.png" 
alt="BLACK">
                            
                        </a>
                    
                </li>
            
        
            
                <li class="selectable column">
                    
                        <a class="swatchanchor" href=
"https://ci.cottonon.com/AU/show-variation/?dwvar_2003013_color=2003013-06&amp;pid=2003013&amp;originalPid=2003013-06";
 
title="Select Colour: EUCALYPTUS" data-attribute-type="color">
                            
                                <img src=
"/on/demandware.static/Sites-Site/-/default/dw0ba6a777/images/noImgLarge.png" 
alt="EUCALYPTUS">
                            
                        </a>
                    
                </li>
            
        
            
                <li class="selectable column">
                    
                        <a class="swatchanchor" href=
"https://xxx.com/AU/show-variation/?dwvar_2003013_color=2003013-07&amp;pid=2003013&amp;originalPid=2003013-07";
 
title="Select Colour: NUDE PINK" data-attribute-type="color">
                            
                                <img src=
"/on/demandware.static/Sites-Site/-/default/dw0ba6a777/images/noImgLarge.png" 
alt="NUDE PINK">
                            
                        </a>
                    
                </li>
            

The element is defined as 

links(:variation_groups, :title => /Select Colour:/)


sleep for 1 section works as below


    def select_variation_group(color)
      variation_groups_elements.map do |el|
         sleep 1
        Watir::Wait.until {el}.wait_until_present.click if el.attribute(
'title').include? "#{color}"
      end
    end

However without sleep fails with trace as below
  def select_variation_group(color)
    variation_groups_elements.map do |el|
      element.wait_until { |el| el.title.include? color }
      element.click
    end
  end
  
Stacktrace:-
      timed out after 10 seconds, waiting for true condition on 
#<Watir::Anchor:
 located: true; {:title=>/Select Colour:/, :tag_name=>"a", :index=>1}> 
(Watir::W
ait::TimeoutError)
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-6.11.0/lib/watir/wait.rb:49:i
n `until'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-6.11.0/lib/watir/wait.rb:125:
in `wait_until'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/page-object-2.2.4/lib/page-object/e
lements/element.rb:176:in `wait_until'
      
C:/git_repo/cog-ui-auto/cuke-tests/features/support/pages/Frontend/Cotton_
On/Pdp_Page.rb:67:in `block in select_variation_group'
      
C:/git_repo/cog-ui-auto/cuke-tests/features/support/pages/Frontend/Cotton_
On/Pdp_Page.rb:63:in `map'
      
C:/git_repo/cog-ui-auto/cuke-tests/features/support/pages/Frontend/Cotton_
On/Pdp_Page.rb:63:in `select_variation_group'
      
C:/git_repo/cog-ui-auto/cuke-tests/features/step_definitions/Pdp_Page_step
s.rb:145:in `block (2 levels) in <top (required)>'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/page-object-2.2.4/lib/page-object/p
age_factory.rb:75:in `on_page'
      
C:/git_repo/cog-ui-auto/cuke-tests/features/step_definitions/Pdp_Page_step
s.rb:144:in `block in <top (required)>'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/glue/in
voke_in_world.rb:39:in `instance_exec'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/glue/in
voke_in_world.rb:39:in `block in cucumber_instance_exec_in'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/glue/in
voke_in_world.rb:54:in `cucumber_run_with_backtrace_filtering'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/glue/in
voke_in_world.rb:27:in `cucumber_instance_exec_in'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/glue/st
ep_definition.rb:110:in `invoke'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/step_ma
tch.rb:31:in `invoke'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/step_ma
tch.rb:24:in `block in activate'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/action.rb:24:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/step.rb:32:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:104:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:51:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:27:in `test_step'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/step.rb:17:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:28:in `block (3 levels) in describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:27:in `each'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:27:in `block (2 levels) in describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/prepare_world.rb:22:in `block in test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/around_hook.rb:17:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:104:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:51:in `execute'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:34:in `around_hook'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/around_hook.rb:12:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:120:in `block (2 levels) in compose_around_hooks'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:121:in `compose_around_hooks'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:26:in `block in describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/runner.rb:19:in `test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:25:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/prepare_world.rb:11:in `test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:25:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:57:in `test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/retry.rb:18:in `test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:25:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/quit.rb:12:in `test_case'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/case.rb:25:in `describe_to'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/broadcast_test_run_started_event.rb:21:in `block in done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/broadcast_test_run_started_event.rb:20:in `map'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/filters
/broadcast_test_run_started_event.rb:20:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/filters/locations_filter.rb:20:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/filter.rb:62:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/test/filters/tag_filter.rb:18:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/compiler.rb:24:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re/gherkin/parser.rb:37:in `done'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re.rb:32:in `parse'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-core-3.1.0/lib/cucumber/co
re.rb:21:in `compile'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/runtime
.rb:75:in `run!'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/lib/cucumber/cli/mai
n.rb:34:in `execute!'
      
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/cucumber-3.1.1/bin/cucumber:9:in `<
top (required)>'
      C:/Ruby24-x64/bin/cucumber:23:in `load'
      C:/Ruby24-x64/bin/cucumber:23:in `<main>'
      features/Store_Stock_Finder-AU.feature:155:in `And the user selects 
the co
lor "black"'


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.

Reply via email to