Finding the index of HTML element Capybara - ruby-on-rails

I am trying to write the step definition, using Capybara, for a Cucumber scenario that is meant to confirm that checkboxes on the home page appear before the options.
Mechanically, I am trying to find the index of a specific html checkbox using its HTML ID and compare it with the index of a specific text on the home page. However, I have spent hours on this issue and have not been able to implement the step definition.
Would I for example be able to somehow convert the page into text and just search for words?
For this web application I am using Ruby on Rails.
Let: checkbox id = environment_Cool
Let: text on the page = Cool
I would greatly appreciate your help.

Suppose you have a checkbox like this:
<form action="demo_form.asp">
<span>
<input type="checkbox" name="coolness" value="Cool" id="environment_Cool" checked> Cool</span>
<br>
<span>
<input type="checkbox" name="coolness" value="Cool"> Not So Cool</span><br>
<input type="submit" value="Submit">
</form>
Mechanically, I am trying to find the index of a specific html
checkbox using its HTML ID
page.find('[#id=environment_Cool ]')
and compare it with the index of a specific text on the home page.
Then it should return the text at the parent of the checklist, which is "Cool".
puts page.find('[#id=environment_Cool ]').find(:xpath,".//..").text

Related

Post form using check boxes does nothing

At this point I'm just trying to getting the input from the form. When I hit submit it does nothing and show nothing in the terminal. I'm using Slim with Sinatra.
My two routes are
post '/user_search' do
puts params[:checkbox]
#slim :user_search_results
# commented because I just would like to see something in terminal.
end
get '/user_search_form' do
slim :user_search_form
end
I've tried creating a class for search as well as a helper method. None of those approaches have changed anything.
Finally here is the form. Granted I have some other forms that work find. Those use text fields, so maybe it is the checkboxes that are throwing things.
form method="POST" action="/user_search"
label for="mp3" mp3:
input type="checkbox" name="mp3" value="mp3"
label for="flac" flac:
input type="checkbox" name="flac" value="flac"
label for="ape" ape:
input type="checkbox" name="ape" value="ape"
label for="m4a" m4a:
input type="checkbox" name="m4a" value="m4a"
label for="jpg" jpg:
input type="checkbox" name="jpg" value="jpg"
label for="gif" gif:
input type="checkbox" name="gif" value="gif"
label for="png" png:
input type="checkbox" name="png" value="png"
input type="submit" value="Submit"
This is non database input. Just want to grab the params for a search method.
Wow, it all came down to indenting all the lines below action method. I also indented submit passed those above. Weird thing is other forms I have, have no indentation at all.

Get Textbox Value in New Page in Sitecore MVC

I am using Sitecore 7.1. I created one search page and created a textbox by using the Web Form For marketer in it. On button click I want catch the text box value in a new page name search-result. How can I catch the WFFFM text box value in New page? I Don't want use JavaScript click event and query string.
<form class="search-form" action="/searchresults" method='get' >
<label><input type="text" name="searchText" id="searchText" placeholder="#placeholderText"></label>
<input type="submit" name="submit" value="" class="#cssClass">
</form>
But i am getting below type of URL
http://www.xyz/searchresults?searchText=searchTextHere&submit=
Can you capture the "onsubmit" event and update the URL to whatever you need using Javascript? You only said not to use onclick event. I'm assuming that you may want to have /searchresults/ as a result. Of course, I assume that your routes are set for this and searchresults can process this correctly.

JQuery Mobile, find a specific input form on a given page

Here is the answer from another question: jQuery find $.find('selector') versus $('selector') difference
The reason this does not work is because find() lets you filter on a set of elements based on a selection you've already made.For example if you wanted to select all of the inputs within a particular form, you could write:
$('#aParticularForm').find('input')
It cannot be called on its own.
How can I expand this statement to find specific inputs on a page? (Specifically listviews)
Working example: http://jsfiddle.net/Gajotres/93VFG/
Wanted element must have a unique identification, like id or class.
HTML :
<form id="aParticularForm">
<input type="text" value="One" id="input1"/>
<input type="text" value="Two" id="input2"/>
</form>
Javascript :
var input = $('#aParticularForm').find('#input1');
alert(input.val());
You can even go further, because you are working with a jQuery Mobile you can have several pages loaded into the DOM and they can all have identical input fields, so to find elements only in a current active page you would use:
$.mobile.activePage.find('#input1');

Rails will_paginate custom renderer manual page number

Hy
What i want to do is to create a custom renderer for will_paginate which renders first, previous, next and last page and a input field where the user can type in the page number manually. I already have the links for first, last etc. but i stuck at the input field. I could create a form in the view but the input field has to be rendered between the previous and next links.
Does anyone know how to do this?
Thanks for your help
You can do this as a separate form (make sure it is a GET). All you
need is the one input element named page. Something as simple as this
should work (not all browsers may like the #). I dropped it into a
site I'm playing with now and it worked. Put it anywhere on your page.
You might have to make something more complicated if you need to
incorporate search terms.
<form action="#" method="get">
Go to page: <input type="text" name="page" value="" size="2"
maxlength="4" />
<input type="submit" name="btnSubmit" />
</form>

How do I change the records being displayed on the page with buttons on the page (RoR)

I have a rails app that shows statistics based on an employee's daily production. currently my page shows ALL records.
I know how to show various different combinations such as records made between two dates etc... but what I really would like to do is make it so that single page (say the index page) has 3 controls that allow for it to switch between daily statistic records, weekly statistic records and a custom date constraint of statistic records (such as from date xx/xx/2009 to date xx/xx/2010). I have been searching for a while to attempt to figure this out but I am obviously missing something as I cannot find anyone else who has run into the same issues.
If this is too difficult to do this way, the other - mostly easy way I can see to do this is to create a page for each view, however it still leaves a question on how I set up the control to choose the custom date constraints.
I aplogise in advance for my newbyness but if someone could explain this to me, I think it is going to really increase my understanding of rails. Thanks in advance
Your control can easily append some information to the query string. Like this form does:
<form action="" method="get">
<fieldset>
<button type="submit" name="show" value="daily">Daily stats</button>
<button type="submit" name="show" value="weekly">Weekly stats</button>
</fieldset>
<fieldset>
From <input type="text" name="interval-start" value="" /> till
<input type="text" name="interval-end" value="" />
<button type="submit" name="show" value="interval">Stats for the specified interval</button>
</fieldset>
</form>
When user clicks on some button, browser sends all form fields to the server-side. On the server-side, in your action, you can check for the show property of the params array. Like this:
#reports = case params["show"]
when "daily"
#Just an example. Use ActiveRecord's query interface or Arel in Rails 3, not plain queries
Report.find_by_sql "SELECT * FROM reports WHERE DATE(report_date) = DATE(NOW())"
when "weekly"
Report.find_by_sql "SELECT * FROM reports WHERE WEEK(report_date) = WEEK(NOW())"
when "interval"
Report.find_by_sql "..."
else
#Some other possible values, filters, so on
end
And in your view just output the #report variable as usual.
You could also create a new route for that filtering, maybe /reports/:name, and avoid using forms. In this case, you only create some links that point to the right filter (/reports/daily, /reports/weekly, etc). On the server-side you need to check reports[:name] for the appropriate value.

Resources