No element found using locator error in protractor - angularjs

In my testing phase I want to test a header element h2 in html
<a class="item-content" ng-href="#/lead/details/1/" target="_self" href="#/lead/details/1/">
<div class="row" style="height: 35px; width: 100%; margin-left:-10px; margin-top: -10px; margin-right: 0px; padding: 0px">
<div class="col col-top col-67">
<h2 class="ng-binding">HAL 9000</h2>
<br>
<h4 style="font-weight: normal; margin-top: -15px" class="ng-binding">Jupiter Feb 10, 2025 </h4>
</div>
<div class="col col-center col-10 col-offset-25" style="margin-right: -10px">
<a href="tel:9876543210" ng-click="$event.stopPropagation()">
<i class="icon ion-ios-telephone-outline" style="font-size: 36px"></i>
</a>
</div>
<div class="col col-center col-20" style="margin-left: 15px">
<a href="mailto:hai#spaceodyssey.com?Subject=Hi;" ng-click="$event.stopPropagation()">
<i class="icon ion-ios-email-outline" style="font-size: 36px;"></i>
</a>
</div>
</div>
</a>
I wanted to test that the "Hal 9000" is visible or not could someone help me to find it in my protractor testing process
in my protractor I used
var child = element(by.css('.col col-top.col-67')), element(by.css('.ng-binding'));
it('20 should update 2nd lead with proper data',function(){
expect(child.getText()).toBe('HAL 9000'); });
and i get an error message in my terminal as
NoSuchElementError: No element found using locator: By.cssSelector(".col col-top.col-67")
someone help me to fix this problen

for a more precise locator, you can always use:
element(by.css('.col.col-top.col-67 h2');

Related

Expression working with static condition but not working with scope object in html file in angularjs

In the below code for Button, I have added ng-disabled condition it is working when I use "qty > 10" but the same condition not working when I add "qty > maxQtySeats" where "maxQtySeats" is my scope variable in which I have assigned value and its printed on html page but not working with condition.
Following is the code of one of the modal
<div class="rectangleSeats">
<div style="width: 300px; float: left;">
<span class="removeSeatstxt" l10n-text="cancellation.removeSeats"></span>
<br/><br/>
<span class="opt-box" style="font-size: 12px;" l10n-text="cancellation.seatstoRemove"></span>
</div>
<div class="quantity buttons_added" style="float: right;">
<form id='myform' ng-app="gemAppSu" ng-controller="ModalInstanceCtrl">
<button ng-click="decrement()" class='qtyminus' ng-disabled="qty<=0" style="background-color: transparent;border: none;">
<img src="assets/img/minus.svg" width="12px" height="12px"/>
</button>
<input ng-model="qty" type='text' name='quantity' id='qty' class='qty' style="font-size: 12px; font-weight: bold;
border: none;height: 44px;width: 52px;text-align: center;"/>
<button ng-click="increment()" style="background-color: transparent;border: none;">
<img src="assets/img/plus.svg" width="12px" height="12px"/>
</button>
</form>
</div>
</div>
<div class="cancellationbtndiv" >
<button type="button" class="btn btn-default nxt-btn" ng-disabled="qty > maxQtySeats">
<span l10n-text="cancellation.buttonnext"></span></button>
</div>
Controller.js
$scope.maxQtySeats = 0;
$scope.maxQtySeats = $scope.activeItem.lineItem.totalQuantity;
Got the solution...
It was a problem of parseInt(), After parseInt($scope.activeItem.lineItem.totalQuantity) it is wokring fine.
Thanks.

p:nth-child(n) not working within css divs

I am trying to control the padding of the first, second and third p tags within a div but can't seem to get it working, below is the code I have
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3">
<div class="icon-box-3 wow fadeInUp" data-wow-delay="0.6s" data-wow-offset="150">
<div class="icon-boxwrap2"><i class="fa fa-medkit icon-box-back2"></i></div>
<div class="icon-box2-title">Free assessments</div>
<p>
We offer FREE 10 minute assessments at our clinics, to see if osteopathy is right for you.
</p>
<div class="iconbox-readmore">FAQs</div>
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3">
<div class="icon-box-3 wow fadeInDown" data-wow-delay="0.9s" data-wow-offset="150">
<div class="icon-boxwrap2"><i data-icon="\e609" class="icon-stethoscope icon-box-back2"></i></div>
<div class="icon-box2-title">Registered</div>
<p>
We are registered osteopaths with the General Osteopathic Council.
</p>
<div class="iconbox-readmore">About</div>
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3">
<div class="icon-box-3 wow fadeInUp" data-wow-delay="1.2s" data-wow-offset="150">
<div class="icon-boxwrap2"><i class="icon-ambulance icon-box-back2"></i></div>
<div class="icon-box2-title">Areas Covered</div>
<p>
The areas generally covered are North London and Hertfordshire, but please do ring to see if we will cover your area.
</p>
<div class="iconbox-readmore">FAQs</div>
</div>
</div>
<style>
.icon-box-3 p:nth-child(1) {
padding: 0 15px 37px 15px;
}
.icon-box-3 p:nth-child(2) {
padding: 0 15px 37px 15px;
}
.icon-box-3 p:nth-child(3) {
padding: 0 15px 37px 15px;
}
</style>
When I do the above, it makes the all three p tags use the same css selector and uses the following line for some reason
.icon-box-3 p:nth-child(3) {
padding: 0 15px 37px 15px;
}
I don't get where it's going wrong?
You need to apply nth-of-type and nth-child classes on parent selector. icon-box-3 is a child under a parent div, which is why your class selection is failing.
.icon-wrapper:nth-of-type(1) p {
background: red;
padding: 0 15px 37px 15px;
}
.icon-wrapper:nth-of-type(2) p {
background: green;
padding: 0 15px 37px 15px;
}
.icon-wrapper:nth-of-type(3) p {
background: blue;
padding: 0 15px 37px 15px;
}
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3 icon-wrapper">
<div class="icon-box-3 wow fadeInUp" data-wow-delay="0.6s" data-wow-offset="150">
<div class="icon-boxwrap2"><i class="fa fa-medkit icon-box-back2"></i></div>
<div class="icon-box2-title">Free assessments</div>
<p>
We offer FREE 10 minute assessments at our clinics, to see if osteopathy is right for you.
</p>
<div class="iconbox-readmore">FAQs</div>
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3 icon-wrapper">
<div class="icon-box-3 wow fadeInDown" data-wow-delay="0.9s" data-wow-offset="150">
<div class="icon-boxwrap2"><i data-icon="\e609" class="icon-stethoscope icon-box-back2"></i></div>
<div class="icon-box2-title">Registered</div>
<p>
We are registered osteopaths with the General Osteopathic Council.
</p>
<div class="iconbox-readmore">About</div>
</div>
</div>
<div class="col-sm-6 col-xs-12 col-md-3 col-lg-3 icon-wrapper">
<div class="icon-box-3 wow fadeInUp" data-wow-delay="1.2s" data-wow-offset="150">
<div class="icon-boxwrap2"><i class="icon-ambulance icon-box-back2"></i></div>
<div class="icon-box2-title">Areas Covered</div>
<p>
The areas generally covered are North London and Hertfordshire, but please do ring to see if we will cover your area.
</p>
<div class="iconbox-readmore">FAQs</div>
</div>
</div>

change id name of carousel by dynamically in angularjs

I have using carousel in my AngularJS App. I want change id of carousel each iteration but it is not working Please tell what did wrong?
<div ng-repeat="data in details">
<div class="carousel" id="{{data._id}}" style=" width: 290px;
max-width: 100% ;
height: 250px;">
<div class="carousel-inner">
<div class="item" ng-class="{active:!$index}" ng-repeat="photo in data.photos">
{{$index}}
<a target="_blank" ui-sref="PhotoUpload">
<img src="{{ photo }}" style=" width: 290px;
max-width: 100% ;
height: 250px;">
</a>
</div>
</div>
<a class="left carousel-control" data-target="#{{data._id}}" ng-non-bindable data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" data-target="#{{data._id}}" ng-non-bindable data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
First carousel image slide are working but after that second carousel images are not working if i click prev and next button first carousel images changing. but second images
Please help me.
I usually handle dynamic id values like this:
[attr.id]="data._id"
and for data-target
[attr.data-target]="'#' + data._id"
There must be possibilities your IDs are same for all elements. Please append {{$index}} within ID.
Try below snippet
id="{{data._id}}_{{$index}}"

connect accordian heading and body through href and id

I have created a bootstrap accordian. When i click an accordian heading, it should show the body contents. I am providing the values dynamically(scope variable) for href and id attributes using angularjs.
But this is not working??
<div class="panel-group col-lg-3" style="background-color:#505054;height:450px" id="accordion">
<div class="panel" style="background-color:#505054;color:#C1C1C1;border-bottom: 1px solid #eee;">
<h6>Clear Filter</h6>
</div>
<div class="panel" style="background-color:#505054;color:white;border-bottom: 1px solid white;" ng-repeat="prdlines in detpline">
<div class="panel-heading">
<h6>
<div class="accordion-toggle" style="cursor:pointer" data-toggle="collapse" data-parent="#accordion" ng-click="plfilter(prdlines.id)" ng-href="{{prdlines.productline_name}}">{{prdlines.productline_name}}</div>
</h6>
</div>
<div ng-attr-id="{{prdlines.productline_name}}" class="panel-collapse collapse">
<div class="panel-body">
<ul id="style-3" style="height:200px; overflow: auto;cursor:pointer">
<li class="panel-title" ng-repeat="prd in detprd"><a ng-click="cfilter(prd.product_name)"><h5>{{prd.product_name}}</h5></a></li>
</ul>
</div>
</div>
</div>
</div>
What is the syntax problem?
For accordian you don't need to specify href and id. Use UI bootstrap.
https://angular-ui.github.io/bootstrap/#/accordion
http://embed.plnkr.co/3y0Rq1/

How to make Accordion Panel-title clickable area bigger

I am trying to make the entire panel-heading click-able. I tried wrapping the div with some css.
plunkr
#box {
padding: 10px;
display: block;
width: 100%;
}
HTML:
<a id="box">
<div class="panel-heading" toggle target="collapse{{$index}}">
<h4 class="panel-title">
<span style="font-size:12px">Name :</span> <span ng-click="selectJob(currentItem, $index)">{{currentItem.JobName}}</span>
</h4>
</div>
</a>
Move ngClick to a element:
<a id="box" ng-click="selectEmployee(employee, $index)">
<div class="panel-heading" toggle target="collapse{{$index}}">
<h4 class="panel-title">
<span>{{employee.firstName}} {{employee.lastName}}</span>
</h4>
</div>
</a>
Demo: http://plnkr.co/edit/nOGHHQWxT5lEKbulmGtJ?p=preview

Resources