How to show or hide a TR tag in Antlr String Template using If Else - stringtemplate

The following is the antlr string template code which I am struggling over. I have a property Item.AmountPaid which might have data (or) could be blank sometimes. So when it has no data I should show Disabled TR and hide Enabled TR and vice-versa. The problem I am facing is whether the property is having data or not, only IF statement is executing every time. Please let me know your valuable suggestions. Thank You for your help!
$
orders: { Item|
$if(Item.AmountPaid)$
<tr class="Enabled">
<td>$Item.AmountPaid$</td>
<td>$Item.Name$</td>
<td>$Item.City$</td>
</tr>
$else$
<tr class="Disabled">
<td>$Item.AmountPaid$</td>
<td>$Item.Name$</td>
<td>$Item.City$</td>
</tr>
$endif$
}
$

The check in an if(expression) clause only works on boolean, null or non-empty values, but not e.g. for empty strings. So make sure the used expression is one of those constructs.

Related

Initial letters missing while using type() in Cypress

Scenario:
<tr>
<td id="type1">
<div><span></span></div>
</td>
<td id="type2">
<div><span></span></div>
</td>
</tr>
cy.get('#type1').type('Abcd') // skips the initial letters ie,
// it actually types 'bcd' or 'cd'
There's an issue here Missing letters when using type #3817. I can see this issue is resolved, but I'm still facing this issue. Any workarounds?
This question leaves out some vital bits that I would like to clear up.
If you try out the click-trick on that HTML snippet, you will come a cropper.
This is the error
cy.type() failed because it requires a valid typeable element.
A typeable element matches one of the following selectors:
a[href]
area[href]
input
select
textarea
button
iframe
[tabindex]
[contenteditable]
The last two are the only options for this particular HMTL, so you could make it work like this:
cy.get('#type1')
.invoke('attr', 'contenteditable') // make it editable
.type('Abcd')
.should('contain', 'Abcd') // confirm it has the text
.invoke('removeAttr', 'contenteditable') // optionally remove the attribute
.should('not.have.attr', 'contenteditable')

How to set the default value of input item with jQuery EasyUI framework

I am trying to set the default value of an input item from last two days.
For this, i have also searched in google but till not cannot find the solution.
I am using jQuery EasyUI framework.
<div class="fitem">
<tr>
<td></td>
<td>
<input type="text" class="easyui-validatebox" name="insertby" id="insertby" size="20">
</td>
</tr>
</div>
<script>
var s = '<?php echo $logname; ?>';
document.getElementById('insertby').value = s ;
alert(s);
</script>
As I am unable to add a comment to ask you to try stuff, I will try my best to help you out!
Firstly, your code works for me. However, there are times where other javascript codes causes errors and stops the code execution before your block of code. You might want to try pressing F12 on your Chrome browser to see if you encounter any errors before your block of code to ensure that all is well.
this code snip might have you
http://www.jeasyui.com/forum/index.php?topic=2623.0
$('#insertby').validatebox('setValue', s);
I took me while to "get it" too.
Actually, jquery easyUI modifies the DOM on the fly to make its fancy things in a way that the original input box is "gone" while you obtain their fancy widget instead. That's why modifying the input field directly has no effect, it is hidden actually. I guess this is done so because their getters/setters should be used in order to update everything correctly.
EasyUI is very easy to set up and play with, but it's way to operate on elements is rather unintuitive. But once you got the hang of it, it should be all right.
Use
setValue. $('idofcombogrid').('setValue',id_value);
The id_value refers to the value of idField as defined initially for the combogrid.

Selenium IDE commnand assertTextPresent not working

I am trying to use the command "assertTextPresent" in the Selenium IDE (Firefox). I configure it this way:
Command: assertTextPresent
Target: <th align="center" abbr="Monday" scope="col" style="background-color:#EFEDF5;font-weight:normal;">Mon</th><th align="center" abbr="Tuesday" (truncated for brevity)
Value: (left empty)
From what I can tell, Selenium is not matching my "target" with the source of the rendered page because of the HTML code in it. So it always fails even though it should pass. How can I make this assert work?
assertTextPresent looks for a value that you specify to be somewhere, anywhere on the page. The value you passed in your target is the text IDE is looking for. It literally is looking for that entire <th> tag as "text" displayed somewhere on the page, which I am assuming it is not displayed.
The correct way to use that function would be to pass the text you are looking for in the target, for example "Mon" or whatever you are looking for. Keep in mind, this is case sensitive. Since this function doesn't care where its looking, you don't specify an actual target. I find in most cases this function to usually not have enough specificity to be reliable.
<tr>
<td>assertTextPresent</td>
<td>Mon</td>
<td></td>
</tr>
I prefer to use assertText or verifyText since it requires a target, allowing you to be more specific where to look for the text.
<tr>
<td>assertText</td>
<td>css=th[abbr="Monday"]</td>
<td>Mon</td>
</tr>
I am not entirely sure the abbr attribute would be a valid selector. There are many ways to target your element, I just use that as an easy example since it was part of your snippit.
if you are testing for a unique text present in a page you can use
Command: assertTextPresent
Target: your search text
here in target you put the text you want to search.
Or
if you want to check for the text present at a position you can use
Command: verifyText
Target: id,name,xpath of the position
value: your search text
Based on what I am seeing here you should be usingassertElementPresent instead of assertTextPresent because you are specifying a element as your target rather than just the text of that <th> element.
If you still want to use assertTextPresent you would simply have "Mon" be your target. Because it's target/argument is what it is searching for.
You likely want 3 parts for an assertTextPresent test:
Command: assertTextPresent
Target: //th[#abbr="Monday"]
Value: Mon
This will look in the cell that contains the attriute #abbr equal to "Monday" and see if the contents (text) is set to "Mon".
To test all the cells you would do multiple assertTextPresent commands one-after-another to test all 7 days.
If you want to go "up a level" you would do something like:
Command: assertTextPresent
Target: //tr
Value: <th align="center" abbr="Monday" scope="col" style="background-color:#EFEDF5;font-weight:normal;">Mon</th><th align="center" abbr="Tuesday" (truncated for brevity)
Normally it is best to try to select an HTML element, like by using a specific attribute, such as id="row_1" or name="first_row". Then your target would be //tr[#id="row_1"] or //tr[#name="first_row"].
Target is the "DOM search syntax" to tell Selenium IDE where to find the text you are looking for. Value is the text to be tested.

Selenium RC link locator cannot find link inside table

I has a page as follow:
<table>
<tr>
<th>Company Name</th>
</tr>
<tr>
<td> What Ever Company</td>
</tr>
</table>
The company name is placed arbitrary in the table, so I can only use the link's text to locate the link:
selenium.click("link='What Ever Company'");
However, it says: ERROR:Element link='What Ever Company' not found.
What is the problem here? Is there any other way to click on the link?
Many thanks.
EDIT
Seem that the problem is I have several links with the same text (my bad). After making the link's text unique, I use selenium.click("//a[contains(text(),'Test Campaign 1756237989')]") and it works.
Could this be because you're forgetting the space at the start of the link?
selenium.click("link=' What Ever Company'");
^
Another possible way of clicking the link, is to use an XPath expression:
selenium.click("//a[contains(.,'What Ever Company')]");
This will match all links with 'What Ever Company' in it.
If you want it more exact:
selenium.click("//a[.=' What Ever Company']");
This will only match if the anchor equals ' What Ever Company'.
Another option is to make the search more specific (i.e. tell the locator this link is always inside a <td> with an <a> inside):
selenium.click("//td[a]/a[contains(.,'What Ever Company')]");
The //td[a] looks for all <td> elements with <a> inside. (Differs from //td/a in that if you look for elements with //td[a][2] you get the second <a> which is inside a <td>, while //td/a[2] on the other hand gets the second <a> of the first <td>.)
EDIT: I thought using . as a reference to text() in the XPath expressions should work, but if it doesn't, try using text() instead.
Try these XPaths:
"//table/tr[2]/td/a"
or
"//a[contains(text(), 'What Ever Company')]"
Should work.

Calculate module of index int Struts2 iterator

I'm using Struts2 iterator to setup a list of checkbox in a table. I want to have 10 checkbox per row, so I'm doing the following:
<table>
<tr>
<s:iterator value="securityMasterFields" status="fieldNameStatus" var="fieldName">
<s:if test="#fieldNameStatus.index % 10 ==0">
</tr><tr>
</s:if>
<td>
<s:checkbox name="fieldsToShow" fieldValue="%{fieldName}" value="%{fieldName}"/>
</td>
</s:iterator>
</tr>
</table>
It never goes through the if, so I'm assuming the mod is not been calculated correctly. How do I do it?
thanks
Well, I had to add some parentheses and it worked correctly. The loop was working, it was just that it wasn't going through the if.
<s:if test="(#fieldNameStatus.index % 8 )==0"></tr><tr></s:if>
It looks good to me. Two thoughts:
1) try printing the result of the test in s:property tag
2) It looks like you will have empty table rows... Are you looking at the generated html or just the output, because if it is just the output then unless you have some CSS giving you some table padding and borders, without an empty 'td' element the row might collapse and make it appear as if nothing is being added. So do make sure you print the empty 'td' elements too!