ServiceNow : Jelly Error - servicenow

I want to print the elements from an array , using foreach loop it is giving error "The prefix j for element j:foreach is not bound".
Below is the code which I wrote:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<h1>Jello World </h1>
<g:evaluate>
var words=['Hello','world','bye'];
</g:evaluate>
<j:foreach var="jvar_word" items="${words}">
<p> ${jvar_word} </p>
</j:foreach>
</j:jelly>

I believe Jelly is case sensitive. Try changing j:foreach to f:forEach.
<j:forEach var="jvar_word" items="${words}">
<p> ${jvar_word} </p>
</j:forEach>

Related

field inheritance in POS (Odoo)

I've added the field 'limit' in 'res.partner' model in 'Sales'. Now, I want to inherit the same in my POS module during the Customer Creation.
I've included all my files(xml and js) in manifest.py with proper syntax.
My '.js' file is working completely fine. The problem shows in 'static/src/xml/pos.xml' file.
Here's my code of pos.xml file. No syntax error, still cant get 'limit' field in POS.
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template_test" xml:space="preserve">
<t t-extend="ClientDetailsEdit">
<t t-jquery=".client-details-right" t-operation="append">
<div class='client-detail'>
<span class='label'>Limit</span>
<input class='detail limit' name='limit' value="5000" readonly="True" t-att-value='partner.limit || ""'></input>
</div>
</t>
</t>
</templates>
Please, tell me if anything is wrong or missing!

xpath. the correct xpath notation.

i am building a webscraper to get the information of a webpage. i want the correct xpath notation to get the information .
<div class="inner">
<div class="col">
<h2>Land in Kadawatha</h2>
<div class="meta">
<div class="date"></div>
<span class="category">Other Lands</span>,
<span class="location">Gampaha</span>
</div>
</div>
how do i access the "Land in Kadawatha" using a xpath.
Standalone XPath 1 without xsl:
//div[contains(concat(" ", #class, " "), " inner ")]/div[contains(concat(" ", #class, " "), " col ")]/h2[1]/a
Using this function:
<xsl:function name="markup:has-class" as="xs:boolean">
<xsl:param name="el" as="element()" />
<xsl:param name="class-name" as="item()" />
<xsl:sequence select="$el/#class and tokenize(upper-case(normalize-space($el/#class)), ' ') = upper-case(string($class-name))" />
</xsl:function>
You can do:
*[markup:has-class(., 'inner')]/*[markup:has-class(., 'col')]//h2/string()
Adjust accordingly depending on your context node.
Based on that snippet
//div[#class='col']/h2/a
then your code would look like
IWebElement element = driver.FindElement(By.XPath("//div[#class='col']/h2/a"));
string elementText = element.Text();

xpath - how to find an embedded li with an input element inside it?

Given this HTML:
<li class="check_boxes input optional" id="activity_roles_input">
<fieldset class="choices">
<legend class="label"><label>Roles</label></legend>
<input id="activity_roles_none" name="activity[role_ids][]" type="hidden" value="" />
<ol class="choices-group">
<li class="choice">
<label for="activity_role_ids_104">
<input id="activity_role_ids_104" name="activity[role_ids][]" type="checkbox" value="104" />Language Therapist
</label>
</li>
<li class="choice">
<label for="activity_role_ids_103">
<input id="activity_role_ids_103" name="activity[role_ids][]" type="checkbox" value="103" />Speech Therapist
</label>
</li>
</ol>
</fieldset>
</li>
I am trying to use Selenium and xpath with it.
I am trying to select the first 'checkbox' input element link.
I am having problems selecting the element.
I cannot use the db ID (104) as this is for repeated tests with new ID's each time. I need to select the 'first' input checkbox, based on it having the text for Language Therapist.
I have tried:
xpath=(//li[contains(#id,'activity_roles_input')])//input
and
xpath=(//li[contains(#id,'activity_roles_input')])//contains('Language Therapist")
but it is not finding the element.
When I do:
xpath=(//li[contains(#id,'activity_roles_input')])
it gets to the input set. The problem I am having is selecting the first input checkbox control for 'Language Therapist'.
First, find any <li> containing the text and than look for in the descendant of those for the first checkbox.
xpath=(//li[contains(., "Language Therapist")]/descendant::input[#type="checkbox"][1])
(From Michael)
The above worked for me. In the end I actually used
xpath=(//li[contains(#id,'activity_roles_input')]/descendant::input[#type="checkbox"][1])
becuase I liked ID'ing by css ID.
interesting fact to notice when I try to run this small xsl against your xml.
XSL:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="//li[#id ='activity_roles_input']">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:
Roles
Language Therapist
Speech Therapist
You have
xpath=(//li[contains(#id,'activity_roles_input')])//input
Shouldn't that be
xpath=(//li[contains(#id,'activity_roles_input')]//input)
or rather
xpath=(//li[#id='activity_roles_input']//input)
?
xpath=(//li[#id='activity_roles_input']//input[1])

Using Watir to verify strike tag exists in html

I have the following html code below that I am using watir to try and verify that March is not have a strike tag and April, June, and July do have strike tag. I'm pretty sure xpath is the key to my answer but have failed at coming up with right solution. Any help is greatly appreciated.
<div class="availability">
Available:
<ul>
<li><span class="month available">March</span></li>
<li><span class="month unavailable"><strike>April</strike></span></li>
<li><span class="month unavailable"><strike>May</strike></span></li>
<li><span class="month unavailable"><strike>June</strike></span></li>
</ul>
</div>
If you are using watir-webdriver, you can do:
#Create an array of the strike elements
months_with_strike = browser.elements(:tag_name, 'strike').collect(&:text)
#Determine if the specified month is in the array
months_with_strike.include?('March')
#=> false
months_with_strike.include?('April')
#=> true
Alternatively, if you only want to check for a single element:
browser.element(:tag_name => 'strike', :text => 'March').exists?
#=> false
browser.element(:tag_name => 'strike', :text => 'April').exists?
#=> true
The important part is that you can get custom elements by using the :tag_name as a locator.
Note: I would think this should also work in watir-classic, but for some reason I am getting exceptions.
Use (assuming the initial context node is the parent of the div element):
div/ul/li/span[not(strike)]
This selects any span elements that doesn't have a strike child (and is a child of a li that is a child of a ul that is a child of a div that is a child of the initial context node)
And use:
div/ul/li/span[strike]
This selects any span elements that has a strike child (and is a child of a li that is a child of a ul that is a child of a div that is a child of the initial context node)
XSLT - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="div/ul/li/span[not(strike)]"/>
==============
<xsl:copy-of select="div/ul/li/span[strike]"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied to the provided XML document:
<div class="availability">
Available:
<ul>
<li><span class="month available">March</span></li>
<li><span class="month unavailable"><strike>April</strike></span></li>
<li><span class="month unavailable"><strike>May</strike></span></li>
<li><span class="month unavailable"><strike>June</strike></span></li>
</ul>
</div>
the two XPath expressions are evaluated and the results (selected nodes) are copied to the output, delimited by a visually distinctive delimiter string:
<span class="month available">March</span>
==============
<span class="month unavailable">
<strike>April</strike>
</span>
<span class="month unavailable">
<strike>May</strike>
</span>
<span class="month unavailable">
<strike>June</strike>
</span>

XPath to find attributes where the name starts with a given value

With this xml:
<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>
<div some="r">d</div>
<div thing="t">f</div>
<div name="y">g</div>
we want to find only
<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>
which are those nodes having an attribute where the attribute name begins with val
You can try this :
//div/#*[starts-with(name(.), 'val')]
if you know that you are looking for the first attribute of the div element.
Edit:
Sorry didn't realize you wanted to select the elements themselves. You could use parent::div or what you did, but the proper way of doing this would be to select directly the div themselves :
//div[#*[starts-with(name(), 'val')]]
have you tried with .../#val* ?
which are those nodes having an attribute where the attribute name
begins with val
Use:
//div[#*[starts-with(name(), 'val')]]
This selects any div element in the document, that has at least one attribute, whose name starts with the string "val".
XSLT - based verification:
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="//div[#*[starts-with(name(), 'val')]]"/>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document (produced from the provided XML fragment):
<html>
<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>
<div some="r">d</div>
<div thing="t">f</div>
<div name="y">g</div>
</html>
selects and outputs the wanted nodes:
<div val1="q">a</div>
<div val2="w">b</div>
<div val3="e">c</div>

Resources