ServiceNow Cart display on Hover - cart

I'm working on a ServiceNow project to display cart on button hover in a header section. The display works successfully on Catalog items, but fails on main page. Any thoughts on why the code works one on page, but not the other?
Catalog Item
Landing Page
<div id="cart_floating_column" class="">
<div id="floating_cart_goes_here" class="cms_cart_container">
</div>
</div>
<j:set var="jvar_use_cart_layouts" value="${gs.getProperty('glide.sc.use_cart_layouts', 'true')}" />
<script>
<j:if test="${jvar_use_cart_layouts == 'false'}">
g_cart_proxy = new CartProxy('floating_cart_goes_here');
</j:if>
<j:if test="${jvar_use_cart_layouts == 'true'}">
g_cart_proxy = new CartProxyV2('floating_cart_goes_here');
</j:if>
</script>

We ended up using an iFrame with a src to a page:
<iframe id="catalog_cart" frameborder="0" src="cart.do"/>
We added the page through Content Management -> Pages. The URL Suffix is "cart". Below is the view of "cart.do". We added content by clicking "Add Content" -> "Catalog Catagories" - > "Shopping Cart".

Related

Using page.at with CSS selector in Mechanize

I am trying to scrape a webpage with Mechanize, with the following structure:
<div id="searchResultsBox">
<div class="listings-wrap">
<div class="listings-header">
<div class="listing-cat">Category</div>
<div class="listing-name">Name</div>
</div>
<ul class="listings">
<li class="listing">
<a href="/ShowRatings.jsp?tid=1143052">
<span class="listing-cat">
<span class="icon"></span>
TEXT
</span>
<span class="listing-name">
<span class="main">TEXT</span>
<span class="sub">TEXT</span>
</span>
</a>
</li>
...
I want to navigate to the page behind the <a> HTML element. Right now, I have:
agent = Mechanize.new
page = agent.get("URL")
page = page.at('#searchResultsBox > div.listings-wrap > ul > li:nth-child(1) > a')
but it keeps returning NIL (verified by puts page.class).
I also tried using sleep to try to ensure that pages have time to load before continuing.
Is there anything I am doing wrong? I thought using the CSS selector would do the trick.
Maybe the website content is loaded dynamically, by JavaScript.
Inspect the content of your page variable and see if the content there is complete or not.
If the content is incomplete, it means that there has to be some other requests, to the serwer returning that data. You can search for them opening Chrome DevTools (or other tool). In the tab "Network" you will see all requests made by website. Search for the one containing data that you need and then scrape it by Mechanize.

XPATH help for web scraper

I need to create a button in Web Scraping Chrome Extension to grab data from a web page but I cant get the next page button to work
<div class="on" onclick="javascript:djxtablePage("_djxid_followup_status_",1)"> > </div>
When you click next button > the code changed to the following
<div class="on" onclick="javascript:djxtablePage("_djxid_followup_status_",2)"> > </div>
Div around the buttons
<div class="dxpaging"> </div>
But I have got it to go forward > and then backwords as it only selects the active button at the start.. XPATH works but as per image it only goes the the 1st active button as there is 4 buttons.
//*[contains(concat( " ", #class, " " ), concat( " ", "on", " " ))]
To get all the buttons use XPATH:
//*[#class='on'][#onclick]
To get all the buttons, if there may another class than on added to the element, use XPATH:
//*[contains(#class,'on')][#onclick]
To get Button 1:
//*[#class="on"][contains(#onclick, '1')]
To get Button 2:
//*[#class="on"][contains(#onclick, '2')]
Above XPaths work on code:
<div>
<div class="on" onclick="javascript:djxtablePage("_djxid_followup_status_",1)">Button 1</div>
<div class="on" onclick="javascript:djxtablePage("_djxid_followup_status_",2)">Button 2</div>
</div>

MVC3: How to render index view and a partial view together on _Layout

So i got a page which have a header, a navigation menu on the left(which is a partial view), and a content on the right(which is an index view). I got a problem in reloading every page's components after navigating menu.
so here's my _Layout
<body>
<div id="header">
<img alt="" src="../../Content/image/asd.png" />
</div>
<div id="menuBar"></div>
<div id="partial">
#RenderBody()
#Html.Partial("MenuPartial")
</div>
i also got a partial view named "MenuPartial" which has list of actionlink(with updateTargetID = "partial") which will update the content of Index.cshtml
and at my homecontroller the ActionResult Index return View()
then i got a little change on _viewStart
#{
Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml";
}
So, what i need is, everytime the actionlink got clicked, the will be updated, my partial view(it has some updated value, so it has to be updated also) and my Index view. And my current result, when i click on action link, the body got rendered, index got updated, but my partial view is gone. anyone has a solution for this?
For your use Case you could perhaps wrap up the #RenderBody() into a div
<div id="content">
#RenderBody()
</div>
Now you can update the content only
$('#content').html("New fancy content")
You can then do the same with the navigation - just make it available as Action in the controller and return PartialView()

Show/hide button: put result into POST variable

I have a long list of links in my website's menu. I show the first three links per default, and I have a "Show/hide" button for the rest of the links.
I would like to be able to change the default value (show or hide) according to the visitor's preference.
--> So the default value is "hide" to start with. If the visitor clicks "show" and then clicks a link, I want the next page to be "show" per default. If he then clicks hide, default is "hide".
Below is my menu. 1-2-3 are always shown, 4-5-6 are shown or hidden.
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<div class="liste-cachee">
<div class="quotecontent">
<div style="display: none;">
<li>4</li>
<li>5</li>
<li>6</li>
</div>
</div>
</div>
<input type="button" value="Plus / Moins" onclick="if (
this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != 'block') {
sendMenuDisplay('block');
this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'block';
} else {
sendMenuDisplay('none');
this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; }" />
</ul>
My question is: How can I save what the visitor choses (show or hide), put it in a $_POST variable and use it as the default value on the next page?
Thanks for your time and help
You could POST or PUT the value and put in a cookie or a session attribute for use in subsequent pages. You could also POST or PUT the value using ajax and put the value in a cookie or session attribute for later use. You could also store the value in a database and use across user-sessions.

Setting div visibility on image click

So I've got an image that inside a tag, and I've also got a div that is centred in the middle of the screen.
How do I make this div invisible until the image is clicked?
Preview of page when the div is visible:
So that added to cart is a div in the middle of the screen. I want that to only show up when the "Add to cart" button has been clicked.
I want the div to go away again after 2 seconds. Transitions would be nice (eg fade into visibility), but I don't mind.
Set the display of the div to none and do a onclick event for the image which sets the display of the div to block. I would recommend using JQuery to add in any transitions or animations.
Something like (without animations):
<div id="cart" style="display:none">
</div>
<img src="imgsource" onClick="document.getElementById('cart').style.display = 'block'"/>
Worked it out. Had to use jQuery.
In the < head> :
<script>
$(document).ready(function(){
$(".addtocart").click(function(){
$(".addedcartbg").fadeIn(500);
$(".addedcartbg").delay(1000);
$(".addedcartbg").fadeOut(500);
});
});
</script>
In the < body> :
<div class="addedcartbg" style="display:none"><div class="addedcart"> Successfully added to cart. </div></div>
css
.hide{
display:none;
}
html
<div class="hide">
// put content here
</div>
<img class="hide-show" src="site.com/image.png" alt=""/>
js
$(function(){
$('.hide-show').bind('click',function(){
$('.hide').fadeIn(500).delay(2000).fadeOut(500);
});
});

Resources