From this particular div below, I am trying to grab the available sizes, which is the "value" property here:
<input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class="">
So I need to return: XS, S, M, L, XL
I have been trying variations of this:
//div[#class='swatch_options']following-sibling::input#value
But this is not working.
<div class="swatch clearfix" data-option-index="0"> <div class="option_title">Size</div> <input id="swatch-0-xs-6072559239" type="radio" name="option-0" value="XS" checked="" class=""> <div data-value="XS" class="swatch-element xs-swatch"> <label for="swatch-0-xs-6072559239">
XS <span class="crossed-out"></span></label></div> <input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class=""> <div data-value="S" class="swatch-element s-swatch available"> <label for="swatch-0-s-6072559239">
S <span class="crossed-out"></span></label></div> <input id="swatch-0-m-6072559239" type="radio" name="option-0" value="M" class=""> <div data-value="M" class="swatch-element m-swatch available"> <label for="swatch-0-m-6072559239">
M <span class="crossed-out"></span></label></div> <input id="swatch-0-l-6072559239" type="radio" name="option-0" value="L" class=""> <div data-value="L" class="swatch-element l-swatch available"> <label for="swatch-0-l-6072559239">
L <span class="crossed-out"></span></label></div> <input id="swatch-0-xl-6072559239" type="radio" name="option-0" value="XL" class=""> <div data-value="XL" class="swatch-element xl-swatch available"> <label for="swatch-0-xl-6072559239">
XL <span class="crossed-out"></span></label></div>
Your xpath syntax for following sibling and input#value are wrong,
try below
//div[#class='swatch clearfix']/input[#name='option-0']
Also, your parent div tag is not closed.
Check the output here
https://codepen.io/ajanth2012/pen/MXaPpp?editors=1010
Related
am creating a rental house management web app whereby a tenant can only review and rate the house in which they are living in only. so in the view, I want to only show the form for the house when the user is logged in, whereby the user can only review that rental house and they can be able to see the form on any other rental house details page except for the rental house they occupies.
i just want only the user to reviewand rate the house they lives in and on the other house descriptions page they won't be able to see a review form.also a user should only have one review for their house house.I have tried this but it shows the for for other rental houses alsoinstead of hiding them.
this is the function that shows the rental house details
public function singlehsedetails ($rental_slug,$id){
$rentalhouse=Rental_house::with
('housetags','rentalalternateimages','houselocation','hsesusers')->find($id);
if (Auth::check())
{
$userrating=Houseratingreview::where(['user_id'=>Auth::user()->id,'hse_id'=>$rentalhouse->id])->first();
}
return view('Front.Rentalslisting.rentalhsedetails',compact('userrating','rentalhouse'));
this is is my blade file.
#if ($userrating ==null)
#else
<div class="card padding-card">
#auth
<div class="card-body" id="ratingdiv">
<h3 class="card-title mb-4">Rate and Review The House</h3>
<span class="font-weight-bold font-italic text-danger">Note:You Can Only Review and Rate Your The House Once</span>
<form id="rateandreviewhseform" method="POST" class="form-horizontal" action="javascript:void(0);">
#csrf
<input type="hidden" name="houseid" value="{{ $rentalhouse->id }}">
<input type="hidden" name="userid" value="{{ Auth::user()->id }}">
<div class="form-group" style="margin-top: 5px;">
<div class="row">
<div class="col-lg-8 col-md-8">
<label style="font-size: 15px;">Give a Star Rating for the House<span class="text-danger">*</span></label>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8">
<div class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="text">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="text">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="text">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="text">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="text">1 star</label>
</div>
</div>
</div>
</div>
<p id="msg" style="font-size: 17px;"></p>
<br>
<div class="control-group form-group" style="margin-top: 2px;">
<div class="controls">
<label style="font-size: 15px;">Write A Review For The House <span class="text-danger">*</span></label>
<textarea style="border:2px solid black;" name="textreview" rows="10" cols="100" class="form-control" required></textarea>
</div>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
#else
<p>To Review and Rate the House Create or Log In to your Account...</p>
<span href="#" data-toggle="modal" data-target="#signupmodal" class="btn btn-success btn-block">Create/Login an Account<i class="fa fa-angle-right"></i></span>
#endauth
</div>
#endif
in my users table i have a column "house_id" that store the house id for the user
this is my ratings and reviews table
public function singlehsedetails ($rental_slug,$id){
$rentalhouse=Rental_house::with
('housetags','rentalalternateimages','houselocation','hsesusers')->find($id);
$userrating=null;
$allowreview=false;
$currentuserlivinginhouse=false;
////check if user is living in the house
if(isset(Auth::user()->house_id) && Auth::user()->house_id==$id){
$currentuserlivinginhouse=true;
}
if (Auth::check())
{
$userrating=Houseratingreview::where(['user_id'=>Auth::user()->id,'hse_id'=>$rentalhouse->id])->first();
//if user is living in the house and rating not given then allow review
if($currentuserlivinginhouse && !isset($userrating->id)){
$allowreview=true;
}
}
return view('Front.Rentalslisting.rentalhsedetails',compact('userrating','rentalhouse','allowreview'));
}
Blade
#if ($allowreview)
<div class="card padding-card">
#auth
<div class="card-body" id="ratingdiv">
<h3 class="card-title mb-4">Rate and Review The House</h3>
<span class="font-weight-bold font-italic text-danger">Note:You Can Only Review and Rate Your The House Once</span>
<form id="rateandreviewhseform" method="POST" class="form-horizontal" action="javascript:void(0);">
#csrf
<input type="hidden" name="houseid" value="{{ $rentalhouse->id }}">
<input type="hidden" name="userid" value="{{ Auth::user()->id }}">
<div class="form-group" style="margin-top: 5px;">
<div class="row">
<div class="col-lg-8 col-md-8">
<label style="font-size: 15px;">Give a Star Rating for the House<span class="text-danger">*</span></label>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8">
<div class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="text">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="text">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="text">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="text">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="text">1 star</label>
</div>
</div>
</div>
</div>
<p id="msg" style="font-size: 17px;"></p>
<br>
<div class="control-group form-group" style="margin-top: 2px;">
<div class="controls">
<label style="font-size: 15px;">Write A Review For The House <span class="text-danger">*</span></label>
<textarea style="border:2px solid black;" name="textreview" rows="10" cols="100" class="form-control" required></textarea>
</div>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
#else
<p>To Review and Rate the House Create or Log In to your Account...</p>
<span href="#" data-toggle="modal" data-target="#signupmodal" class="btn btn-success btn-block">Create/Login an Account<i class="fa fa-angle-right"></i></span>
#endauth
</div>
#endif
I properly define everything in my back end file. When I try to use
the back end variables in Thymeleaf by using selection variable
expression it is not working. It show errors in every field:
cannot resolve field name
register.html
<!doctype html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:replace="/fragments/head"></head>
<body>
<nav th:replace="/fragments/nav :: nav-front"></nav>
<div class="container-fluid mt-5">
<div class="row">
<div th:replace="/fragments/categories"></div>
<div class="col"></div>
<div class="col-6">
<h3 class="display-4">Register</h3>
<form method="post" th:object="${user}" th:action="#{/register}" >
<div th:if="${#fields.hasErrors('*')}" class="alert alert-danger">
There are errors
</div>
<div class="form-group">
<label for>Username:</label>
<input type="text" class="form-control" th:field="*{username}" placeholder="Username">
<span class="error" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></span>
</div>
<div class="form-group">
<label for>Password:</label>
<input type="password" class="form-control" th:field="*{password}">
<span class="error" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></span>
</div>
<div class="form-group">
<label for>Confirm Password:</label>
<input type="password" class="form-control" th:field="*{confirmPassword}">
<span class="error" th:if="${passwordMatchProblem}">Passwords do not match</span>
</div>
<div class="form-group">
<label for>E-mail:</label>
<input type="email" class="form-control" th:field="*{email}" placeholder="E-mail" required>
<span class="error" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></span>
</div>
<div class="form-group">
<label for>Phone number:</label>
<input type="text" class="form-control" th:field="*{phoneNumber}" placeholder="Phone number">
<span class="error" th:if="${#fields.hasErrors('phoneNumber')}" th:errors="*{phoneNumber}"></span>
</div>
<button class="btn btn-danger mb-5">Register</button>
</form>
</div>
<div class="col"></div>
</div>
</div>
<div th:replace="/fragments/footer"></div>
</body>
</html>
I get errors everywhere I use the selection expression field.
Are you adding "user" to your model in your controller?
You need to add it to your model so Thymeleaf can access it.
addAttribute method can be used like so: model.addAttribute("user", myUser);
I have a controller ( Laravel ) which will be dynamic create a form as below
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<div class="col-2">
<form class="addform" id="newcheckform" role="form">
'.csrf_field().'
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</form>
</div>
</div>
if will be loaded by below script in the blade file
$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");
The form displayed as its should to be.
However I when I submit button. Nothing happened. code as below. Appreciate anyone can help. this script resides in the same blade file.
$(function() {
$(document).on('submit', '#newcheckform', function(e){
alert("Hi");
});
});
You have wrong closing tags for <form> change something like this:
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<form class="addform" id="newcheckform" role="form">
{{csrf_field()}}
<div class="col-2">
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</div>
</form>
</div>
This will work.
this is the html part when i add more email id's only first email is being validated and rest of emails treat as normal even if they are not in proper
<form action="<?php echo base_url()?>index.php/EMail/show_email">
<div class="form-group">
<label for="exampleInputEmail1">To :</label>
<input type="email" name="toa[]" ng-model="to" placeholder="To" class=" tagsinput" value="ss" />
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject :</label>
<input type="text" class="form-control" ng-model="sub" name="suba" id="exampleInputEmail1" placeholder="Subject">
<div>{{sub}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">CC :</label>
<input type="text" class="form-control" ng-model="to" name="cca" id="exampleInputEmail1" placeholder="CC">
<div>{{to}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">BCC:</label>
<input type="text" class="form-control" name="bcca" id="exampleInputEmail1" placeholder="BCC">
</div>
<div class="form-group ">
<label for="ccomment" class="control-label">Message</label>
<textarea class="form-control " id="ccomment" name="msg" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<input type="submit" onclick="mail()" class="btn btn-primary" value="Send"/>
<button type="submit" class="btn btn-Success">Draft</button>
</form>
this is my controller and "toa "is that field which i mentioned in the image
function show_email(){
$this->form_validation->set_rules("toa[]","To","valid_email");
$this->form_validation->set_rules("cca","CC ","valid_email");
$this->form_validation->set_rules("suba","Subject","required");
$this->form_validation->set_rules("bcca","bcc","valid_email");
$this->form_validation->set_rules("msg","Message","required");
if($this->form_validation->run()==FALSE){
$data["title"]="EMail";
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view('Mail/mail');
}else{
//finish
$ccdata=$this->input->post("cca");
$bccdata=$this->input->post("bcca");
$sub=$this->input->post("suba");
$ms=$this->input->post("msg");
$dataa["username"]="MyProject";
$dataa["msg"]=$ms;
$msg=$this->load->view('Email_Temp/mail',$dataa,TRUE);
$todata=explode(",",$data);
print_r($todata[0]);
//$this->SendEmail($todata,$ccdata,$bccdata,$msg,$sub);
}
}
[Image] this is the field (to) that i want to validate
I have text that says 'Roles'. After that there are two checkboxes.
I can get to 'Roles'.
How can I get to and click check the checkboxes?
I am trying to use:
xpath=(//label[contains(text(),'Roles')]/div/span/input)
but getting not found.
My HTML is:
<div class="control-group string required">
<label class="string required control-label" for="survey_name">
<abbr title="required">*</abbr> Name</label>
<div class="controls">
<input class="string required" id="survey_name" name="survey[name]" size="50" type="text" /></div>
</div>
<div class="control-group check_boxes required">
<label class="check_boxes required control-label">
<abbr title="required">*</abbr> Roles
</label>
<div class="controls">
<span class="checkbox">
<input class="check_boxes required" id="survey_role_ids_121" name="survey[role_ids][]" type="checkbox" value="121" />
</span>
</div>
</div>
</div>
The div is not a child of the label, is is a following-sibling. Therefore, the XPath expression you need is
//label[contains(., "Roles")]/following-sibling::div/span/input