Protractor-Not able to select item from drop down - protractor

I am trying to select item from drop down using the code:
var assettype= element(by.model("templateIdTracker"));
if (assettype.isDisplayed()) {
assettype.click();
}
browser.sleep(1000);
element(by.cssContainingText('option', 'A')).click();
I can click the drop down but on trying to select item, it throws error:
"Failed: element not visible: Element is not currently visible and may
not be manipulated"
This is the web page code. Please suggest.
<div class="k-list-container k-popup k-group k-reset k-state-border-up" data-role="popup" style="position: absolute; font-size: 14px; font-family: "Open Sans Light","Helvetica Neue",Helvetica,Arial,sans-serif; font-stretch: normal; font-style: normal; font-weight: 400; line-height: 20px; width: 243.5px; height: auto; display: block; transform: translateY(0px);">
<div class="k-list-optionlabel ng-scope"/>
<div class="k-group-header" style="display:none"/>
<div class="k-list-scroller" unselectable="on" style="height: auto;">
<ul class="k-list k-reset" unselectable="on" tabindex="-1" aria-hidden="false" aria-live="off" data-role="staticlist" role="listbox">
<li class="k-item ng-scope k-state-hover" data-offset-index="0" unselectable="on" role="option" tabindex="-1">A</li>
<li id="1ebaaa3b-8f44-4873-b478-fea6fd498b83" class="k-item ng-scope k-state-selected k-state-focused" data-offset-index="1" unselectable="on" role="option" tabindex="-1">B</li>
<li class="k-item ng-scope" data-offset-index="2" unselectable="on" role="option" tabindex="-1">C</li>
<li class="k-item ng-scope" data-offset-index="3" unselectable="on" role="option" tabindex="-1">D</li>
<li class="k-item ng-scope" data-offset-index="4" unselectable="on" role="option" tabindex="-1">E</li>
<li class="k-item ng-scope" data-offset-index="5" unselectable="on" role="option" tabindex="-1">F</li>
<li class="k-item ng-scope" data-offset-index="6" unselectable="on" role="option" tabindex="-1">G</li>
</ul>
</div>
</div>
</div>
</div>

You could implement helper method to wait for this element to be visible.
Helpers.expectVisible = function (elementLocator, elementDescription) {
var message = null;
if (elementDescription) {
message = elementDescription + ' was not visible';
}
return browser.wait(EC.visibilityOf(elementLocator), WAIT_TIMEOUT, message);
};

you can also try:
assettype.click();
element(by.linkText("A")).click();

The problem is your browser can't see the element, its probably on the bottom of the screen.
You can use the same solution to any element you cant see.
Check my answer here https://stackoverflow.com/a/39074330/1431062

Thanks all!
It simply worked by using 'li' instead of 'option'
element(by.cssContainingText('li', 'A')).click();
instead of element(by.cssContainingText('option', 'A')).click();
assettype= element(by.model("templateIdTracker"));
assettype.click();
browser.sleep(1000);
element(by.cssContainingText('li', 'A')).click();
browser.sleep(2000);

Related

Swiper.js active slide reach data attribute

I can't find a solution to a problem. I have a page with more swiper.js sliders.
I try to reach the data attributes of the just changed slide, but I get undefended.
<h1>Slider 1</h1>
<div class="mySwiper swiper-h" id="id1">
<div class="swiper-wrapper">
<div class="swiper-slide" data-contetntdata1="contentdata1" data-contetntdata2="contentdata2">Content</div>
<div class="swiper-slide" data-contetntdata1="contentdata1" data-contetntdata2="contentdata2">Content</div>
<div class="swiper-slide" data-contetntdata1="contentdata1" data-contetntdata2="contentdata2">Content</div>
</div>
</div>
<h1>Slider 2</h1>
<div class="mySwiper swiper-h" id="id1">
<div class="swiper-wrapper">
<div class="swiper-slide" data-contetntData1="contentDataTxt1" data-contetntdata2="contentDataTxt2">Content</div>
<div class="swiper-slide" data-contetntData1="contentDataTxt1" data-contetntdata2="contentDataTxt2">Content</div>
<div class="swiper-slide" data-contetntData1="contentDataTxt1" data-contetntdata2="contentDataTxt2">Content</div>
</div>
</div>
<script>
const swiper = new Swiper(".mySwiper", {
on: {
slideChangeTransitionEnd: function () {
*console.log($(this)).find('.swiper-slide-activ').data('contetntData1');
console.log($(this)).find('.swiper-slide-activ').data('contetntData2');*
},
},
});
</script>
One solution is to use swiper api slides[] (array) and realIndex (And get the data attribute value by custom JS dataset).
on: {
realIndexChange: function () {
let index = this.realIndex + 1; /* slide 1 => slides[1] */
let current_data = this.slides[index].dataset.city;
console.log(current_data);
}
}
Demo (Jquery)
let swiperCMSglobalSetting = {
// Optional parameters
slidesPerView: 1,
// Enable lazy loading
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
},
on: {
realIndexChange: function () {
let index = this.realIndex + 1; /* slide 1 => slides[1] */
let current_data = this.slides[index].dataset.city;
$("#status").text(current_data);
},
}
}
$(".swiper").each(function(index, element){
var $this = $(this);
var swiper = new Swiper(this, swiperCMSglobalSetting);
});
html,
body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
}
.swiper {
width: 100%;
height: 50%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link
rel="stylesheet"
href="https://unpkg.com/swiper#7/swiper-bundle.min.css"
/>
<!-- Slider main container -->
<h1>status: <span id="status"></span></h1>
<div class="swiper one">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide" data-city="london _ 1.1">london _ 1.1</div>
<div class="swiper-slide" data-city="paris _ 1.2">paris _ 1.2</div>
<div class="swiper-slide" data-city="moscow _ 1.3">moscow _ 1.3</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<hr>
<!-- Slider main container -->
<div class="swiper two">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide" data-city="dublin _ 2.1">dublin _ 2.1</div>
<div class="swiper-slide" data-city="amsterdam _ 2.2">amsterdam _ 2.2</div>
<div class="swiper-slide" data-city="madrid _ 2.3">madrid _ 2.3</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
<script src="https://unpkg.com/swiper#7/swiper-bundle.min.js"></script>

chartJS generateLegend()

I'm new in using chart JS, I am trying to customize the legends. I try the example that I found but when I try to make my own it shows this error.
I want to display the legends in separate like in this.
here's my code.
var myLegendContainer = document.getElemenById('legend');
var graphTarget = $("#line-chartcanvas");
graphTarget.attr('height',80);
barGraphQty = new Chart(graphTarget, {
type: 'bar',
data: chartdata,
options: {
legend: {
display: false
},
}
});
myLegendContainer.innerHTML = barGraphQty.generateLegend();
});
HTML code
<div class="col-md-4">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Legends</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<div id="legend"></div>
</div>
</div>
</div>
CSS
[class$="-legend"] {
list-style: none;
cursor: pointer;
padding-left: 0;
}
[class$="-legend"] li {
display: block;
padding: 0 5px;
}
[class$="-legend"] li.hidden {
display:block !important;
text-decoration: line-through !important;
}
[class$="-legend"] li span {
border-radius: 5px;
display: inline-block;
height: 10px;
margin-right: 10px;
width: 10
please help me.
Without seeing your code, it's almost impossible to tell why exactly this TypeError occurs. From the posted image, I deduct however that the use of generatelabels is not the ideal choice to achieve what you need.
What you really need is generating custom HTML legend using legendCallback together with some CSS.
Please take a look at the following posts to see how this could be done:
https://stackoverflow.com/a/63216656/2358409
https://stackoverflow.com/a/63202664/2358409

How to create a sortable picture gallery?

I want to create a youtuber gallery (or table I don't know) with avatar pictures that would be sortable by sexe, country, age... (ideally with settings on the side).
Pictures would include interactive several links and I would also like visitors to know what youtubers are live when consulting the list/table.
Thanks a lot in advance... ))
I can't give you more than a library recommendation here, but I think something like this is the way to go: Have a look at Isotope, a JS library to generate "Filter & sort magical layouts". It looks pretty much like what you want.
The demo on the site linked above basically says it all. You can see the code for the demo in this codepen (also taken from the site linked above).
How it works is that you feed your markup with meta data for the respective elements and the library gives you the filter & sort functionality and displays a grid layout with your elements:
<div class="element-item metalloid " data-category="metalloid">
<h3 class="name">Tellurium</h3>
<p class="symbol">Te</p>
<p class="number">52</p>
<p class="weight">127.6</p>
</div>
Then it's simple to have filter buttons for the grid like this:
<button class="button" data-filter=".metal">metal</button>
(samples from the codepen!)
I hope this hint helps you - it certainly gives you more control then ready-made Youtube gallery (if there is one at all, I don't know) - but in turn you'll have to get your hands a little dirty writing up the code.
Check out jQuery UI sortables "Display as Grid":
https://jqueryui.com/sortable/#display-grid
You can do something like this:
<ul id="sortable">
<li class="ui-state-default">
<img src="something.png">
</li>
</ul>
$( function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
} );
#sortable {
list-style-type: none;
margin: 0;
padding: 0;
width: 450px;
}
#sortable li {
margin: 3px 3px 3px 0;
padding: 1px;
float: left;
width: 100px;
height: 90px;
font-size: 4em;
text-align: center;
background: #ddd;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<ul id="sortable">
<li class="ui-state-default">1</li>
<li class="ui-state-default">2</li>
<li class="ui-state-default">3</li>
<li class="ui-state-default">4</li>
<li class="ui-state-default">5</li>
<li class="ui-state-default">6</li>
<li class="ui-state-default">7</li>
<li class="ui-state-default">8</li>
<li class="ui-state-default">9</li>
<li class="ui-state-default">10</li>
<li class="ui-state-default">11</li>
<li class="ui-state-default">12</li>
</ul>

Normal (vertical) form inside form-horizontal with Twitter Bootstrap

I would like to have a form which has a horizontal layout on the first level, but then within one row there can be a form "inline" which I want to have a vertical (the default) layout. Is there an easy way to achieve this?
Note: .form-inline doesn't do what I'm looking for, as it doesn't put the inside labels on top of the inputs.
So far I have something like this:
<div class="form-horizontal">
<div class="control-group">
<label class="control-label">
outer label
</label>
<div class="controls ### SOMETHING TO CLEAR/OVERRIDE form-horizontal ###">
### INLINE FORM WITH SAME STRUCTURE IS HERE ###
</div>
</div>
</div>
Boostrap can't do this by default, but I've included this in my fork https://github.com/jasny/bootstrap/blob/master/less/jasny-forms.less#L40
Please consider using Jasny's extensions to Bootstrap http://jasny.github.com/bootstrap
or just use this CSS
.form-vertical .form-horizontal .control-group > label {
text-align: left;
}
.form-horizontal .form-vertical .control-group > label {
float: none;
padding-top: 0;
text-align: left;
}
.form-horizontal .form-vertical .controls {
margin-left: 0;
}
.form-horizontal .form-vertical.form-actions,
.form-horizontal .form-vertical .form-actions {
padding-left: 20px;
}
.control-group .control-group {
margin-bottom: 0;
}
With the HTML
<form class="form-horizonal">
# Horizal controls here
<div class="form-vertical">
<div class="control-group">
<label class="control-label">Label</label>
<div class="controls">Something here</div>
</div>
</div>
</form>
Here is #jasny-arnold-daniels CSS updated for Boostrap 3. In 3 form-group replaces control-group, form-control replaces control. Also needs #user9645 's change to width. New CSS is:
.form-vertical .form-horizontal .form-group > label {
text-align: left;
}
.form-horizontal .form-vertical .form-group > label {
float: none;
padding-top: 0;
text-align: left;
width: 100%
}
.form-horizontal .form-vertical .form-control {
margin-left: 0;
}
.form-horizontal .form-vertical.form-actions,
.form-horizontal .form-vertical .form-actions {
padding-left: 20px;
}
.form-group .form-group {
margin-bottom: 0;
}
You do not need to write custom CSS for Bootstrap 3. Instead of putting your class of form-horizontal on the form tag, only put a wrapper div with that class around the form elements that you want to be horizontal (and supporting column-size classes for the horizontal items).
For example, this would work:
<form>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">I'm a horizontal form element</label>
<div class="col-sm-10">
<input type="text" class="form-control">
</div>
</div>
</div>
<div class="form-group">
<label>I'm a vertical form element</label>
<input type="text" class="form-control">
</div>
</form>
This works because the vertical form is automatically used for a form with no class explicitly stated. That 'lack of a class' can be seen in the docs here.
I was unsure exactly what you were looking for but I tried to guess.
I made a form with a two vertical lines the second line with multiple form elements.
I used inline-block to do this.
http://jsbin.com/icoduh/1/edit

JQuery sortable does not drop on overflow list items

I have two lists - the first contains a list of items the user can select, and he selects them by dragging them to the second list. I have implemented this with jQuery UI Sortable, and created a basic example on jsfiddle.
So drag an item from the first to the second list - OK. The problem occurs if you scroll down to the bottom of the second list - you are unable to drag an item from the first to the second list. It appears that all list items that overflowed beyond the end of the visible list do not have a drop target associated with them. Same happens when copying in the other direction.
As sortable appears to be aimed at lists, I suspect I am missing a trick. Any ideas?
The jsfiddle example code is:
html
<div class="listDiv">
<ul id="list1" class="connected ui-sortable">
<li id="a">a</li>
<li id="b">b</li>
<li id="c">c</li>
<li id="d">d</li>
<li id="e">e</li>
<li id="f">f</li>
<li id="g">g</li>
<li id="h">h</li>
<li id="i">i</li>
<li id="j">j</li>
</ul>
</div>
<div class="listDiv">
<ul id="list1" class="connected ui-sortable">
<li id="1">1</li>
<li id="2">2</li>
<li id="3">3</li>
<li id="4">4</li>
<li id="5">5</li>
<li id="6">6</li>
<li id="7">7</li>
<li id="8">8</li>
<li id="9">9</li>
<li id="10">10</li>
<li id="11">11</li>
<li id="12">12</li>
<li id="13">13</li>
<li id="14">14</li>
<li id="15">15</li>
</ul>
</div>
js
$(function() {
$( "#list1, #list2" ).sortable({
connectWith: ".connected"
}).disableSelection();
});
css
.listDiv {
overflow:auto;
float: left;
width:400px;
border: 1px solid #999;
}
#list1, #list2 {
list-style-type: none;
height: 200px;
}
#list1 li, #list2 li {
font-size: 11px;
margin: 0 5px 5px;
padding: 5px;
width: 300px;
border: 1px solid #C5DBEC;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-weight: bold;
outline: medium none;
}​
I believe I have nailed down the version of jquery ui sortable in which the bug was introduced - 1.8.12. The following code appears to cause the error:
//We ignore calculating positions of all connected containers when we're not over them
if(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0])
continue;
I have reported this on jquery ui bug 4231 in the hope that they will reopen this (unfixed) bug and fix it in a future release.
So if you are struggling with this problem you can check if the bug has been fixed, or revert back to jquery ui 1.8.11, or otherwise remove the offending code mentioned above and hope for the best!