Check the check box in a table - ruby

In my application I have check any one of the check box and click on save button. I used with table as follows to select the option, but it doesnt work:
# with in table, set
within_table('countryTable') do
find(:xpath, "//tbody/tr/td[1]/checkbox").set(true)
end
click_button('Save')
but its not working.....
Select countries for this owner
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxAU' name='AU' value='AU' />
</td>
<td>
Australia
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCA' name='CA' value='CA' />
</td>
<td>
Canada
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxFR' name='FR' value='FR' />
</td>
<td>
France
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGG' name='GG' value='GG' />
</td>
<td>
Guernsey
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxJP' name='JP' value='JP' />
</td>
<td>
Japan
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxNZ' name='NZ' value='NZ' />
</td>
<td>
New Zealand
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxZA' name='ZA' value='ZA' />
</td>
<td>
South Africa
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxCH' name='CH' value='CH' />
</td>
<td>
Switzerland
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxAE' name='AE' value='AE' />
</td>
<td>
United Arab Emirates
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxGB' name='GB' value='GB' />
</td>
<td>
United Kingdom
</td>
</tr>
<tr>
<td class='first'>
<input type='checkbox' id='CheckboxUS' name='US' value='US' />
</td>
<td>
United States
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>

You can reach the check box by id, css, or xpath.
# to check the FR with xpath
find(:xpath, "//input[#name='FR']").click()
# to check the FR with id
find(:id, "CheckboxFR").click()
# to check the FR with css
find(:css, "#CheckboxFR").click()
if you want to use within_table which narrow the scope:
within_table(find(:id, "table_id")) do
find(:id, "id_of_option").click()
end

Related

List only records populated with Capybara

Friends helped me with a solution that validates if there are [active/inactive] records in the list. When I list the records using pp capybara also returns blank lines. How do I disregard empty records?
def validate_active_inactive_records
expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/)
# ***listing records***
page.all('.tvGrid tr > td:nth-child(5)').each do |td|
puts td.text
end
end
<table width="100%" class="tvGrid">
<tbody>
<tr>
<th colspan="1" class="tvHeader">Id</th>
<th colspan="1" class="tvHeader">Code</th>
<th colspan="1" class="tvHeader">Description</th>
<th colspan="1" class="tvHeader">Operational Center</th>
<th colspan="1" class="tvHeader">Status</th>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="tvRowEmpty">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
Are you asking how to remove the rows with the class tvRowEmpty from your search results? If so, you can use the :not operator in your finder:
def validate_active_inactive_records
expect(page).to have_css("td:nth-child(5)", :text => /^(ACTIVE|INACTIVE)$/)
# ***listing records***
page.all('.tvGrid tr:not(.tvRowEmpty) > td:nth-child(5)').each do |td|
puts td.text
end
end
If you want to exclude any td that just contains you could use the following finder with a regex that filters tags containing only whitespace characters:
page.all('.tvGrid tr > td:nth-child(5)', text: /[\s]^*/).each

Thymeleaf th:block condition

I want to set up some conditions on Thymeleaf templates like this, but it doesn't work.
<table border=2>
<thead>
<tr>
<td> Identifiant </td>
<td> Nom Formation </td>
<td> Descirption Formation </td>
<td> Adresse Formation </td>
<td>Status Formation </td>
<td> Chef Projet </td>
<td> Formateur </td>
<td>Ressource Humain</td>
<td>Update</td>
<td>Liste Devellopeur</td>
</tr>
</thead>
<tbody>
<tr th:each="formations : ${formations}">
<th:block th:if="${StatusFormation}} =='Traitement' }">
<td th:text="${formations.id}"> </td>
<td th:text="${formations.NomFormation}"> </td>
<td th:text="${formations.DescriptionFormation}"> </td>
<td th:text="${formations.StatusFormation}"> </td>
<td th:text="${formations.AdresseFormation}"> </td>
<td th:text="${formations.chef_projet}"> </td>
<td th:text="${formations.formateurs}"> </td>
<td th:text="${formations.ressourcehumain}"> </td>
</th:block>
</tr>
</tbody>
</table>
the erros is
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${StatusFormation}} =='Traitement' }" (template: "ChefProjetFormationHome" - line 29, col 11) at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:131)
The problem is you add one extra brace in this line:
<th:block th:if="${StatusFormation}} =='Traitement' }">
you should change it to:
<th:block th:if="${StatusFormation} == 'Traitement'">

Looping through a table twice

I'm trying to create a page that has a table. The table has a service and then the items under the service so the table should look like this
<table class="table table-striped table-bordered table-condensed pricing_table">
<tr>
<td></td>
<td>
Short
</td>
<td>
Medium
</td>
<td>
Long
</td>
</tr>
<tr>
<td>
Cut & Blow Dry
</td>
<td>
R170
</td>
<td>
R190
</td>
<td>
R220
</td>
</tr>
<tr>
<td>
Blow Dry
</td>
<td>
R120
</td>
<td>
R170
</td>
<td>
R190
</td>
</tr>
<tr>
<td>
Girls under 18
</td>
<td>
R130
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
Pensioners
</td>
<td>
R130
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
Gents Cut
</td>
<td>
R120
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
Boys Cut
</td>
<td>
R90
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
Upstyles - Trail
</td>
<td>
R270
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
Upstyles
</td>
<td>
R350
</td>
<td></td>
<td></td>
</tr>
</table>
but what I'm getting is this
<table class="table table-striped table-bordered table-condensed pricing_table">
<tbody>
<tr>
<td> Cutting & Styling </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Cut & Blow Dry </td>
<td> 150 </td>
<td> 170 </td>
<td> 190 </td>
</tr>
<tr>
<td> Cutting & Styling </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Blow Dry </td>
<td> 100 </td>
<td> 120 </td>
<td> 140 </td>
</tr>
<tr>
<td> Cutting & Styling </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Girls under 18 </td>
<td> 120 </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> Cutting & Styling </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Pensioners (Ladies) </td>
<td> 70 </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Color </td>
<td> 150 </td>
<td> 200 </td>
<td> 250 </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Half Head Foils </td>
<td> 200 </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Full Head Foils </td>
<td> 300 </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Per Foil </td>
<td> 10 </td>
<td> 15 </td>
<td> 20 </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Brazilian </td>
<td> 700 </td>
<td> 800 </td>
<td> 900 </td>
</tr>
<tr>
<td> Chemical Service </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Perm </td>
<td> 150 </td>
<td> 170 </td>
<td> 190 </td>
</tr>
<tr>
<td> Treatment </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Salon Treatment </td>
<td> 100 </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> Treatment </td>
<td> Short </td>
<td> Medium </td>
<td> Long </td>
</tr>
<tr>
<td> Olaplex - Stand Alon </td>
<td> 180 </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
The service is always being looped and displayed. I would only like the service to be looped once and the items to be displayed under their respective service.
My pricing.blade.php
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 about_content_area">
<h1>pricing</h1>
<div class="col-lg-5 col-lg-offset-3 col-md-5 col-md-offset-3 pricing_wrapper">
<table class="table table-striped table-bordered table-condensed pricing_table">
#foreach($services_options as $services)
#foreach($services->service as $service)
<tr>
<td>
{!! $service->title !!}
</td>
<td>
Short
</td>
<td>
Medium
</td>
<td>
Long
</td>
</tr>
#endforeach
<tr>
<td>
{!! $services->title !!}
</td>
<td>
{!! $services->short !!}
</td>
<td>
{!! $services->medium !!}
</td>
<td>
{!! $services->long !!}
</td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
My controller
public function content($id)
{
$menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
$menu = Menu::where('id', $id)->firstOrFail();
$layout = $menu->type;
$gallery_category = Gcategory::all();
$services_options = Price::all();
return view('open::public/'.$layout, compact('menus_child', 'menu', 'gallery_category', 'services_options'));
}
You have a loop for the header part of the table (the short, medium, long part) within the loop for each service, which is why its being output above each service row.
You just need to update pricing.blade.php to be the following
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 about_content_area">
<h1>pricing</h1>
<div class="col-lg-5 col-lg-offset-3 col-md-5 col-md-offset-3 pricing_wrapper">
<table class="table table-striped table-bordered table-condensed pricing_table">
<tr>
<td></td>
<td>
Short
</td>
<td>
Medium
</td>
<td>
Long
</td>
</tr>
#foreach($services_options as $services)
<tr>
<td>
{!! $services->title !!}
</td>
<td>
{!! $services->short !!}
</td>
<td>
{!! $services->medium !!}
</td>
<td>
{!! $services->long !!}
</td>
</tr>
#endforeach
</table>
</div>
</div>
</div>

Microsoft VBScript compilation error '800a03f6' Expected 'End'

I cannot figure it out why i keep getting error as below:
VBScript compilation error '800a03f6'
Expected 'End'
I suspect the error come from below code, but I am not sure which part was the main reason of the error.
<% if objRS.state = 1 then objRS.close
set objRS = nothing
objDB.close
set objRS = nothing
set objDB = nothing
%>
can anyone help me out?
I put the most of the code below.
<div class="content span9">
<div class="panel">
<h2 class="title">Donation</h2>
<div class="panel_content">
<form name="eForm" id="eForm" method="post" action="reg_prc.asp" onsubmit="return verify();" AUTOCOMPLETE="off">
<table width="70%" align="center">
<%
strSQL = "SELECT M.*, C.fldName AS fldCountryName FROM tblMembership M INNER JOIN tblCountry C ON M.fldCountryID=C.fldID WHERE M.fldID=" & cSQLStr(objSession.getVal("UserID"))
objDB.getRec strSQL, errNo, errDesc, objRS
if objRS.eof then
else
dim strStatus
if objRS("fldStatus") = "A" then
strStatus = "ACTIVE"
elseif objRS("fldStatus") = "D" then
strStatus = "DISABLED"
end if
%>
<tr>
<td>
<table width="90%" align="center">
<!-- Username -->
<tr>
<td width="34%" align="right"> <%=larr(74)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><b><%=objRS("fldCode") %></b></td>
</tr>
<tr>
<td> </td>
</tr>
<!-- Coporate -->
<tr>
<td width="34%" align="right"><%=larr(75)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><input type="text" name="txtICNo" id="txtICNo" maxlength="30" size="30" onkeypress="return changeKey(this, event, filterText);"/></td>
</tr>
<tr>
<td> </td>
</tr>
<!-- Address -->
<tr>
<td width="34%" align="right"><%=larr(82)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><b><%=objRS("fldAddress1") %></b><!--<input type="text" name="txtAddress1" id="txtAddress1" maxlength="200" size="50" />--> </td>
</tr>
<tr>
<td width="34%" align="right"></td>
<td width="1%" align="center"></td>
<td width="65%" align="left"><b><%=objRS("fldAddress2") %></b><!--<input type="text" name="txtAddress2" id="txtAddress2" maxlength="200" size="50" />--> </td>
</tr>
<tr>
<td width="34%" align="right"></td>
<td width="1%" align="center"></td>
<td width="65%" align="left"><b><%=objRS("fldAdress3") %></b><!--<input type="text" name="txtAddress2" id="Text1" maxlength="200" size="50" />--></td>
</tr>
<tr>
<td width="34%" align="right"></td>
<td width="1%" align="center"></td>
<td width="65%" align="left"><b><%=objRS("fldCity") %></b><!--<input type="text" name="txtAddress2" id="Text2" maxlength="200" size="50" />--></td>
</tr>
</tr>
<tr>
<td width="34%" align="right"></td>
<td width="1%" align="center"></td>
<td width="65%" align="left"><b><%=objRS("fldstate") %></b><!--<input type="text" name="txtAddress2" id="Text2" maxlength="200" size="50" />--></td>
</tr>
<tr>
<td> </td>
</tr>
<!-- mobile phone number -->
<tr>
<td width="34%" align="right"><%=larr(88)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><b><%=objRS("fldMobileNo") %></b><!--<input type="text" id="txtMobileNo" name="txtMobileNo" maxlength="20" value="" />--> </td>
</tr>
<tr>
<td> </td>
</tr>
<!-- Email Address -->
<tr>
<td width="34%" align="right"><%=larr(441)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><b><%=objRS("fldEmail") %></b><!--<input type="text" id="txtEmail" name="txtEmail" maxlength="50" value="" size="40" />--></td>
</tr>
<tr>
<td> </td>
</tr>
<!--Quantity of trees donation -->
<tr>
<td width="34%" align="right"><%=larr(89)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left">
<select name="slctTreeQty" id ="slctTreeQty" onblur="calDonationAmt()" onchange="calDonationAmt()">
<option value="0">Please Select Quantity of Tree</option>
<option value="10">10</option>
<option value="100">100</option>
<option value="1000">1000</option>
<option value="10000">10,000</option>
<option value="100000">100,000</option>
</select>
<span class="style1" style="font-size:small">*Every Tree cost USD10</span> </td>
</tr>
<!-- total amount of donation -->
<tr>
<td width="34%" align="right"><%=larr(90)%></td>
<td width="1%" align="center">:</td>
<td width="65%" align="left"><span id="totalDonationAmt" style="font-weight:bold"></span></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" align="center">
<tr>
<td align="center">
<table>
<tr>
<td><input type="submit" name="btnPayment" id="btnPayment" value="<%=larr(168)%>"/></td>
<td><input type="submit" name ="btnContact" id="btnContact" value="<%=larr(81)%>" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div><!--end of panel content-->
</div><!--end of panel-->
</div><!--end of content-->
</body>
<% if objRS.state = 1 then objRS.close
set objRS = nothing
objDB.close
set objRS = nothing
set objDB = nothing
%>
</html>
As per Lankymart's pointer:
if objRS.eof then
else
dim strStatus
if objRS("fldStatus") = "A" then
strStatus = "ACTIVE"
elseif objRS("fldStatus") = "D" then
strStatus = "DISABLED"
end if
...
END IF <=========================================
Alternatively, you could code this properly:
If Not objRS.eof Then
dim strStatus
if objRS("fldStatus") = "A" then
strStatus = "ACTIVE"
elseif objRS("fldStatus") = "D" then
strStatus = "DISABLED"
end if
...
End If
I suspect that the final End If needs to go before your closing </table> tag.
I notice that you're not checking to see if any data is being returned (i.e. both EOF and BOF.
Try to avoid tables for layout - there's just no reason to use them, try using divs instead.

reCAPTCHA keep saying incorrect-captcha-sol

I have this form
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<tr>
<td width="32%" valign="top"> <strong class="main_title">Select Category: </strong></td>
<td width="68%" valign="top" class=""><? $qu="SELECT `id`,`name` FROM `linkvideos_category` WHERE `status` = '1'"; $rs=$Q($qu); ?>
<select name="category" class="blacktext" >
<option>Choose Category</option>
<? while($dis=$F($rs)) { ?>
<option value="<?=$dis['id']?>"> <?=$dis['name'];?></option>
<? } ?>
</select></td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td valign="top"> <strong class="main_title">Upload Image: </strong></td>
<td valign="top" class=""><input type="file" name="imagefile" /> </td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td valign="top"> <strong class="main_title"> Your Link : </strong></td>
<td valign="top" class=""><input name="link" type="text" size="50" /></td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td valign="top"> <strong class="main_title"> Link Title : </strong></td>
<td valign="top" class=""><input name="linkname" type="text" size="50" /></td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td valign="top"> <strong class="main_title">Description:</strong></td>
<td valign="top"><label>
<textarea name="desc" cols="40" rows="10"></textarea>
</label></td>
</tr>
<tr>
<td valign="top"> <strong class="main_title">Security Code:</strong></td>
<td valign="top">
<? if ($error==3) { ?>
<font color="red">Invalid Code Entered</font>
<?}?>
<?php
require_once('captcha/recaptchalib.php');
echo recaptcha_get_html($public_key);
?></td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td colspan="2" valign="top" class=""> </td>
</tr>
<tr>
<td colspan="2" align="center" valign="top" class=""><input type="submit" name="Submit" value="Submit" class="btns" onclick="javascript:return check();" /></td>
</tr>
</form>
and i'm verifying the captcha with this
$resp = recaptcha_check_answer ($private_key,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$error = 3;
echo"<script>window.location='submit_linkvideo.php?error=3';</script>";
}
and every time it's telling me the captchas invalid and saying incorrect-captcha-sol, am I missing something? I've tested it and the recaptcha values arn't being submitted.
Fixed it by ending a table before the form then starting the table again once inside the form.

Resources