In Tritium,how to select li which have the same class as other? - moovweb

<ul class="parent">
<li class="abc">1</li>
<li class="abc">2</li>
</ul>
How to select li which have the same class as other?

$('./ul[#class="parent"]/li[contains(text(),"1")]') This is a way you can select any li using text function

This will also work:
$('//ul[#class="parent"]/li[1]') #Targets the first "<li>".
$('//ul[#class="parent"]/li[2]') #Targets the second "<li>".

Related

How to stop querying when it reaches a specific class with XPath?

Say I have the following:
<div class="data">
<h2 class="entry-contentH2">Preparation</h2>
<h2>Airplanes</h2>
<ul>
<li><strong>3 large</strong> wings</li>
<li><strong>2</strong>doors</li>
</ul>
<h2>Car</h2>
<ul>
<li><strong>4</strong> doors</li>
<li><strong>1 cup</strong> holder</li>
</ul>
<h2 class="stopHeader">Execution</h2>
<h2>Motorcycles</h2>
<ul>
<li>Easy to learn</li>
</ul>
</div>
I'm trying to get query all of the <p></p> tags text after the <h2>Preparing</h2>, but I want it to stop at the last <p></p> before the stopHeader class.
This is the code that I came up with:
//h2[contains(.,"Preparation")]/following-sibling::h2/text()[not(preceding::h2[#class="stopHeader"])]
#and also
//h2[contains(.,"Preparation")]/following-sibling::h2/text()[not(preceding::h2[contains(., "Execution")])]
Try below XPath to get desired output:
//h2[.="Preparation"]/following-sibling::h2[./following-sibling::h2[.="Execution"]]/text()
This should return text content of each header (h2) between "Preparation" and "Execution"
Try this xpath.
//h2[text()='Preparation']/following::h2[not(#class='stopHeader')]/text()

How to find sibling element with behat/mink?

HTML:
<div id="my-id">
<li class="list_element">
<div class="my_class"></div>
</li>
<li class="list_element">
<div class="another_class"></div>
</li>
<li class="list_element">
<div class="class3"></div>
</li>
</div>
What I want to do with behat/mink:
$page = $this->getSession()->getPage();
$selector = $page->find('css', "#my-id .my_class"); //here I need anchor element located near to .my_class div.
I don't know in which one .list_element .my_class div is. I know only anchor is next to .my_class element. Which selector should I use in the find() function?
Try one of these:
#my-id .my_class ~ a
#my-id .my_class + p
#my-id .list_element a
This is too basic question.Please see more here w3schools

executing java/scala code in scala.html templates

Can I execute that line of code
nav = request().path().toString()
inside of scala template like index.scala.html
I would like to have that code to check on witch side is user and to mark it on menu
using code like this in main.scala.html:
<li class="#("active".when(nav == "contact"))">
Contacts
</li>
I would recommend you different approach, create tag - resuable template, which takes Integer as an argument,
it will render menu and mark as an active different menuitem depends on value.
#(menuItem: Int)
<ul >
<li #if(menuItem==1){ class="active" } >
////
</li>
<li #if(menuItem==2){ class="active" }>
</li>
<li #if(menuItem==3){ class="active" }>
///
</li>
</ul>
from your contact page and any other page, call this tag with corresponding value, #views.html.tags.menu(1)
You can define variables like that if that is your question. If it is not your question than please try to explain your problem in more detail.
#nav = { #request().path().toString() }

jQuery selector to get last child that doesnt have a class

I have a page of nested ULs and LIs, I need to get the last LI of each UL, so I'm doing:
$('li:last-child')
this works great.
But I need to extend this so it gets the last child LI of each UL, where the LI doesn't have a given class (x). For example:
<ul>
<li class="x">1</li>
<li>2</li>
<li class="x">3</li>
<li>4</li>
<li>5</li>
<li class="x">
6
<ul>
<li class="x">7</li>
<li>8</li>
<li class="x">9</li>
<li>10</li>
<li>11</li>
<li class="x">12</li>
<li class="x">13</li>
</ul>
</li>
</ul>
I need to return LI 5 and 11 (as these are the last children within their parent ul that don't have .x)
How can I do this elegantly?
Use the map()(docs) method to create a jQuery object by iterating over the <ul> elements, and returning the last child <li> element without an x class.
Example: http://jsfiddle.net/e2Da7/2/
var lastLisNoX = $('ul').map(function() {
return $(this).children('li:not(.x)').get(-1);
});
EDIT: Updated my jsFiddle example with the HTML that was posted in the question.
Filter out the elements with a class.
$('li:not(.x):last-child')
If the classes are different amongst the li elements, that is if all the elements are not class="x" then something like
$('li[class=""]:last-child')

select li having images

I want to apply ifixpng function, for li having images , but i cannot select the below image and apply ifixpng function , how can i select
<li style="list-style-image: url("http://images.abbottnutrition.com/Glucerna.com.br-HCP/IMAGES/bullet.png");"> abc </li>
Isn't better to have the style in css?
And it's easier to select it
css:
.image{
list-style-image: url("http://images.abbottnutrition.com/Glucerna.com.br-HCP/IMAGES/bullet.png")
}
js:
$('li .image').some_func()
Solution:
$('ul li[style*="list-style-image"]').foo()
and the html should be with normal ':
<li style='list-style-image: url("images.abbottnutrition.com/Glucerna.com.br-HCP/IMAGES/…; abc </li>