hide specific child element from an html using prototype - prototypejs

using prototype, I am trying to hide the specific children element of a particular element.
From the html below, I want to hide child ul and all of its element:
<ul>
<li id="category_1" class="active">
<strong id="img_1" class="cat_plus"></strong>
<input type="checkbox" name="cat_id[]" value="1">
<ul>
<li id="category_3">
<strong id="img_1" class="cat_plus"></strong>
<input type="checkbox" name="cat_id[]" value="3">Root Catalog
</li>
</ul>
<li>
</ul>
i tried:
$('category_1 ul').hide();

I think this is what you are looking for.
$$('#category_1 ul').first().hide();
See fiddle
I hope it helps.

Related

XPath: Select any div that contains one or more descendant divs with a specific class

Assume that following HTML snippet exists somewhere in the <body> element of a web page:
<div id="root_1000" class="root bacon">
<ul>
<li id="item_1234567" class="active">
<div class="userpost author_4281">
<div>This text should be visible.<div>
</div>
<ul><li>Some item</li></ul>
</li>
</ul>
</div>
<div id="root_2000" class="root bacon">
<ul>
<li id="item_8675309" class="active">
<div class="userpost author_3333">
<div>
This text, and as the DIV.root that contains it, should be hidden.
<div>
</div>
<ul><li>Another item</li></ul>
</li>
</ul>
</div>
<div id="root_3000" class="root bacon">
<ul>
<li id="item_7654321" class="active">
<div class="userpost author_9877">
<div>This text should be visible.<div>
</div>
<ul><li>Yet another item</li></ul>
</li>
</ul>
</div>
So here's my question: what would the XPath syntax be to select the div.root that contains info posted by author #3333 (i.e. div[class~="author_3333"])?
The following XPath statement will properly match the div.userpost element associated with author #3333 that I want to hide, but does not include the <ul><li>Another item</li></ul> node, which I also need to hide:
.//div[contains(#class, 'author_3333')]
What I want to do is select the closest div.root ancestor associated with the node that my XPath statement matches. Any help would be greatly appreciated... thanks in advance!
you need to get the parent node that has the second div as its child, something like:
//div[.//div[contains(#class, "author_3333")]]
You can use this XPath expression:
.//div[contains(#class, 'author_3333')]/ancestor::div[contains(#class,'root')][1]
Output is:
<div id="root_2000" class="root bacon">
<ul>
<li id="item_8675309" class="active">
<div class="userpost author_3333">
<div>
This text, and as the DIV.root that contains it, should be hidden.
</div>
</div>
<ul>
<li>Another item</li>
</ul>
</li>
</ul>
</div>

How to find xpath in label class?

Can someone assist, I need to identify the xpath that's inside label class for the last ticket-type. The .html code is as below.
<div class="vertical-accordion">
<ul id="accordion-5" class="accordion">
<li class="open-li">
<a class="toggle-link open" href="#">
<span>Tickets on your smart card</span>
</a>
<div class="accordion-drop" style="display: block;">
<ul>
<li>
<li>
<li>
<label class="ticket-type">megarider</label>
<label class="validity"> (7 day: 16 June to 22 June 2016 ) </label>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
</div>
</div>
</div>
</article>
If you want to find the last ticket-type, I assume that there are multiple ticket type...
You didn't provide a lot of HTML, I'll answer with that assumption :
//label[#class='ticket-type'][last()]
Hope it'll help !
You can use this xpath to find the element in your example:
//label[#class='ticket-type'][1]
Open up this page using Chrome, Hit F12 Developer tools, Inspect the element, find the label in the F12 window (Elements Tab) right click on the label tag and select Copy -> Copy XPath

How to select the las Li with Xpath or Css Selector

I want to select the text in the last li with xpath, i can use Css Selector too.
here the value is "3"
<div class="pg">
<input type="hidden" value="1" name="PaginationForm.CurrentPage">
<input id="PaginationForm_TotalPage" type="hidden" value="41" name="PaginationForm.TotalPage">
<span class="pgPrev">‹</span>
<ul>
<li class="">
<span class="current">1</span>
</li>
<li class="">
<a>2</a>
</li>
<li class="">
<a>3</a>
</li>
</ul>
<a class="jsNxtPage pgNext">›</a>
</div>
i try this in Selenium
driver.find_elements_by_xpath('(//*[#class="pg"]/ul/li/text())[last()]')
As the method name suggests, it can only return element, not text node. You can find the target <a> element first :
a = driver.find_element_by_xpath('//*[#class="pg"]/ul/li[last()]/a')
And then you can get the inner text from a.text

How to fill my html with json object?

I am new in ajax.
I am trying to get value and want to fill in html code snippet.
I have html code and json object that has value.
Now I want to show the specific value in the different-different part of html code.
Here is my html code:-
<div>
<div class="borb clearfix">
<div class="profileholder fleft">
<img src="images/users/1.png" class="userpic">
<div class="icon state green"></div>
</div>
<div class="remainder">
<div class="padl10">
<div class="username">Anurag Shivpuri</div>
<div class="desig">Cheif Information Officer</div>
<div class="loc">Credit Operation | Pune</div>
</div>
</div>
</div>
<ul class="userdata">
<li>
<span class="lbl">Employee Code :</span>
<span> 2007</span>
</li>
<li>
<span class="lbl">Role_Designation :</span>
<span> Senior HR</span>
</li>
<li>
<span class="lbl">Department :</span>
<span> HR</span>
</li>
<li>
<span class="lbl">Sub_Department :</span>
<span> Talent Acquisition</span>
</li>
<li>
<span class="lbl">Official E-mail Id :</span>
<span> atul.gupta#bajajfinserve.co.in</span>
</li>
<li>
<span class="lbl">Mobile No :</span>
<span> 9844333932</span>
</li>
</ul>
<div class="footbar">
Reward
Incentive
Movement
Leaves
LnD
</div>
On success of ajax I am getting the value now I want to fill it in my html code.
Please help me.
You can use a library (like knockout) to do that, or you can use jQuery to create the elements:
$("<div>").append("some text").appendTo("body"); //creates a div, append some text and...
If you already have a success event in your ajax, you could grab an empty DOM element and set its content.
document.getElementById('placeholder').innerHTML = jsonData.myProperty;
You should use innerHTML in javascript.
Set some ID on the element you need to update:
<li>
<span class="lbl">Employee Code :</span>
<span id='employeeCode'> 2007</span>
</li>
Then update it with your json value:
document.getElementById('employeeCode').innerHTML= yourJsonObject.employeeCodeValue;

How capture dynamically populated dropdown list ids in Capybara

I am using Capybara,Rspec and Ruby for my development. I am having drop down list which is populated with values with dynamic ids because of which I am not able locate the element correctly. Here is HTML code. I tried to get the solution from this site as well as by googling. But I couldn't get the correct solution
when I am doing the firebug I am getting Xpath as //[#id='select2-result-label-8'] and every time I am getting new id in the last meaning, next time if I go I will get it as //[#id='select2-result-label-11']. How to resolve this issue. I am having similar issues with my group of check box also. Hope this solution will help there also
<ul id="Values" class="check" role="listbox">
<li class="Reports " role="presentation">
<div id="select2-result-label-3" class="history" role="option">
<span class="same"/>
Add New
</div>
</li>
<li class="Reports-highlighted" role="presentation">
<div id="select2-result-label-4" class="history" role="option">
<span class="same"/>
Multiple
</div>
</li>
<li class="Reports" role="presentation">
<div id="select2-result-label-5" class="history" role="option">
<span class="same"/>
Last
</div>
</li>
</ul>

Resources