Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Capybara Scoping

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 525
    Comment on it

    There are many times when we want to restrict our search to a particular section and not on the whole page. This will basically decrease the search time and will also help in uniquely identifying the desired element. Capybara provides within method through which we can restrict our scope of search. Let's suppose we have the following HTML:

    <div>
    <ul id ="menu1" class="bottomNavList" style="clear: both;margin-bottom:0;">
    	<li class="myContent">My Content </li>
    	<li class="recordDesktopList myReports">My Reports</li>
    	<li class="recordDesktopList myReports activePro">My Active Projects</li>
    	<li class="blankBg hireProject">Hire</li>
    </ul>
    <ul id ="menu2" class="bottomNavList" style="clear: both;margin-bottom:0;">	
    	<li class="recordDesktopList">Post Projects</li>
    	<li class="postBlogsTech browzNerd">Browse Nerds</li>
    	<li class="blankBg workProject">Work</li>
    	<li class="projectFind">Find Projects</li>
    </ul>
    </div>

     

    Now, we want to locate "My Content" section, so we can restrict our scope within "menu1" section to increase the efficiency of search.

    within ('#menu1') do
    	content = @session.find('.myContent').text
    	puts "Value = #{content}"
    	end
    end

    Capybara also provides some element specific within method:

    • within_frame
    • within_fieldset
    • within_window
    • within_table

    within_frame: This method will restrict the search scope within the given iframe only.
        within_frame(frame_id)

        Eg:

    within_frame 'mainiframe' do
       content = @session.find('.myContent').text
       puts "Value = #{content}"
    end

    within_fieldset: This method will restrict the search scope within the given iframe only.

    within_window: This method will restrict the search scope within the given window only.

    within_table: This method will restrict the search scope within the given table only.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: