Best way to add class to link with ui-sref? - angularjs

What's the best way to add a class to link that uses ui-sref="state1"?
My issue is that I have my menu outside the ui-view.
<ul>
<li>
<a data-ng-class="{active: active=='dash'}" data-ui-sref="dash">Dashboard</a>
</li>
<li>
<a data-ui-sref="reports">Reports</a>
</li>
</ul>
<div data-ui-view="main"></div>
I am trying to highlight the active link but not quite sure what the best method would be in this scenario?

You can do that using the ui-sref-active directive:
<ul>
<li>
<a ui-sref-active="active" data-ui-sref="dash">Dashboard</a>
</li>
<li>
<a data-ui-sref="reports">Reports</a>
</li>
</ul>
<div data-ui-view="main"></div>

function myFunction() {
$("[ui-sref='state1']").addClass('newClass');
}
$(document).ready(myFunction);
.newClass{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<ul>
<li>
<a data-ng-class="{active: active=='dash'}" data-ui-sref="dash">Dashboard</a>
</li>
<li>
<a data-ui-sref="reports" ui-sref='state1'>Reports</a>
</li>
</ul>
<div data-ui-view="main"></div>

Related

Ordered Lists Inside ShieldUI Accordion

Is it possible to include an ordered list inside a ShieldUI accordion? Including one seems to break my accordion; I'm hoping there is some sort of flag or work around to get ordered lists working.
<div class='accordion-container'>
<h2>Delivery Instructions</h2>
<ul id='accordion'>
<li>
<h2>Vehicle Delivery to Media / Client</h2>
<p>Accordion 1</p>
<li>Header
<ol>
<li>One</li>
<li>Two</li>
</ol>
</li>
</li>
<li>
<h2>Delivery to Airport</h2>
<p>Accordion 2</p>
</li>
</ul>
</div>
Try putting it in a DIV, like this:
<div class='accordion-container'>
<h2>Delivery Instructions</h2>
<ul id='accordion'>
<li>
<h2>Vehicle Delivery to Media / Client</h2>
<p>Accordion 1</p>
<li>
<h2>Header</h2>
<div>
<ol>
<li>One</li>
<li>Two</li>
</ol>
</div>
</li>
</li>
<li>
<h2>Delivery to Airport</h2>
<p>Accordion 2</p>
</li>
</ul>
</div>

How to use Jquery inside reactjs

I need question about using jquery inside of reactjs.
I just need to write dropdown sidebar menu using jquery.
But i do not know how to use jquery inside of react function.
Please help me.
In my Case:
<nav class="sidebar">
<div class="text">Side Menu</div>
<ul>
<li class="active">
Dashboard
</li>
<li>
<a href="#" class="feat-btn">
Features
<span class="fas fa-caret-down first"></span>
</a>
<ul class="feat-show">
<li>
Pages
</li>
<li>
Elements
</li>
</ul>
</li>
<li>
<a href="#" class="serv-btn">
Services
<span class="fas fa-caret-down second"></span>
</a>
<ul class="serv-show">
<li>
App Design
</li>
<li>
Web Design
</li>
</ul>
</li>
<li>
Portfolio
</li>
<li>
Overview
</li>
<li>
Shortcuts
</li>
<li>
Feedback
</li>
</ul>
</nav>
The jquery Code is here:
$('.btn').click(function(){
$(this).toggleClass("click");
$('.sidebar').toggleClass("show");
});
$('.feat-btn').click(function(){
$('nav ul .feat-show').toggleClass("show");
$('nav ul .first').toggleClass("rotate");
});
$('.serv-btn').click(function(){
$('nav ul .serv-show').toggleClass("show1");
$('nav ul .second').toggleClass("rotate");
});
$('nav ul li').click(function(){
$(this).addClass("active").siblings().removeClass("active");
});
I searched in google but did not find it.
PLEASE I NEED HELP!

css selector to retrieve nodes without any id

I only want to catch the first list item with a css selector.
That can i do?
<ul>
<li class="someclass"> </li>
<li id="thisId" class="someclass"> </li>
<li id="thatId" class="someclass"> </li>
<li id="someId" class="someclass"> </li>
<ul>
ul li.someclass:first-child{
}

how to click on nav menu list items using selenium web driver

Somebody please suggest me how can i click on menu in selenium web driver. I am trying to find out by css selector and directly by id,link text but its not work:
driver.findElement(By.cssSelector("nav > ul a#user")).click();
Help is highly appreciated. Below is the code:
<nav>
<ul style="">
<li class="">
<a id="dashboard" title="Dashboard" href="ajax/dashboard.html">
</li>
<li>
<a id="controlpanel" href="ajax/controlpanel.html">
</li>
<li class="active">
<a id="user" href="ajax/user.html">
</li>
<li class="open">
<a id="audcon" title="client" href="#">
<b class="collapse-sign">
</a>
<ul style="display: block;">
<li>
<a id="client" href="ajax/client.html">
</li>
<li>
<a id="stores" href="ajax/location.html">
</li>
<li>
<a id="sub_category" href="ajax/auditgroup.html">
</li>
<li>
<li>
</ul>
</li>
<li>
<a id="quescon" href="#">
<ul>
</li>
<li>
<li>
<a id="help" href="guidelines.html">
</li>
</ul>
</nav>
Try Following
driver.findElement(By.id("user")).click();
OR
driver.findElement(By.xpath("//li[#class='active']")).click();

CLick UL tag using Selenium WEBdriver

I have a HTML code as mentioned below with UL tag, and I wanted to click the UL tag Manage -> Channel using Selenium Webdriver. To do that I have written the below code in java but it is not working, infact no error is throwing but page is getting opened. Please help.
HTML
<ul class="adb-primary_nav--items adb-layout-default">
<li class="adb-primary_nav--item">
<a class="adb-primary_nav--link en" href="../">
<img class="adb-primary_nav--image" src="https://d33na3ni6eqf5j.cloudfront.net/marketplace_logo/img1474715110198223685.png?7ef040694410736c21450bea763bb661" alt="Vodafone Group">
</a>
</li>
<li class="adb-primary_nav--item">
<a class="adb-primary_nav--link" id="myapps" href="../myapps">
MyApps
</a>
</li>
<li class="adb-primary_nav--item">
<a class="adb-primary_nav--link" id="shop" href="../home">
Marketplace
</a>
</li>
<li class="adb-primary_nav--item"><a class="adb-primary_nav--link" id="developer" href="../cms/home">Developer</a></li>
<li class="adb-primary_nav--item js-drainable-menu">
<div class="adb-context_menu adb-js-context_menu">
<a id="manage" class="adb-context_menu--trigger adb-js-context_menu--trigger adb-primary_nav--link admin-item selected" role="button" tabindex="0">Manage</a>
<div class="adb-container adb-context_menu--menu adb-js-context_menu--menu" role="menu">
<ul class="adb-stack">
<li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content" href="../corporate/home">Corporate</a></li>
<li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content selected" href="./marketplace">Channel</a></li>
<li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content" id="account" href="../account/home">Account</a></li>
</ul>
</div>
</div>
</li>
<li class="adb-primary_nav--item adb-primary_nav--item__right">
<div class="adb-context_menu adb-js-context_menu" data-placement="right">
<a class="adb-context_menu--trigger adb-js-context_menu--trigger adb-primary_nav--link" role="button" tabindex="0">testchannel user</a>
<div class="adb-container adb-context_menu--menu adb-js-context_menu--menu" role="menu">
<ul class="adb-stack">
<li class="adb-stack--item">
<a class="adb-link__option adb-stack--item_content" id="myProfile" href="../profiles/5944276">My Profile</a>
</li>
<li class="adb-stack--item">
<a class="adb-link__option adb-stack--item_content" id="myCompany" href="../companies/219288">My Company</a>
</li>
<li class="adb-stack--item">
<a class="adb-link__option adb-stack--item_content" id="mySettings" href="../settings">My Settings</a>
</li>
<li class="adb-stack--item">
<a class="adb-link__option adb-stack--item_content" id="logout" href="../logout">Logout</a>
</li>
</ul>
</div>
</div>
</li>
</ul>
Java Code
Configuration_file var = new Configuration_file();
System.setProperty("webdriver.chrome.driver", "C:\\Users\\gur29175\\workspace\\SAAS\\jars\\chromedriver.exe");
WebDriver firefox_dri = new ChromeDriver();
firefox_dri.get(var.env_URL + "/home");
firefox_dri.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
firefox_dri.findElement(By.cssSelector("a:(*'Manage'*)")).click();
firefox_dri.findElement(By.cssSelector("a:(*'Channel'*)")).click();
driver.findElement(By.xpath("//a[#id='manage']")).click()
driver.findElement(By.xpath("//ul[#class='adb-stack']/li[2]")).click()
In case of a listbox, you need to get the list of elements and iterate over it to choose the required element.
Please share the screenshot of the page with dropdowns. Will be able to guide you with the code.
You can replace
firefox_dri.findElement(By.cssSelector("a:(*'Manage'*)")).click();
firefox_dri.findElement(By.cssSelector("a:(*'Channel'*)")).click();
with
firefox_dri.findElement(By.linkText("Channel")).click();
Try it
//ul[#class='adb-stack']/li[#class='adb-stack--item']/a[contains(text(),'Corporate')].click();

Resources