I'm using plone and trying to display a form result in a page template.
I'm trying to filter some database results using tal:condition with a python expression but it always evaluates to false.
The code looks like this:
<tr tal:repeat="result view/results">
<td> <span tal:condition="python:view.teams[0]==result.team_id" tal:replace="result/position">Position</span></td>
<td> <span tal:condition="python:view.teams[1]==result.team_id" tal:replace="result/position">Position</span></td>
</tr>
I want the table cells to be filled with the team position when the team id is matched in the result, but the cells always are empty.
If I remove the tal:condition from the span and replace the tal:replace="result/position" with tal:replace=python:view.teams[0]==result.team_id it prints True or False so I can check that the result is correct.
Can anyone help me about this issue? Why does tal:condition allways evaluate false?
I'd fully expect this to work, so something else must be wrong.
Python expressions such as yours are commonplace; there are several examples on the internet to show they do normally work.
Try further debugging the values with tal:replace="python:repr(view.teams)" and tal:replace="python:repr(result.team_id)" statements and similar to be 100% certain of what your data structures look like.
Related
I am trying to output a table using handlebars.
Right now it loops through the each row, and then through each column, but how can I grab the data from the row based on {{col.name}}?
See here, I need to get COLUMNNAME from {{col.name}}
{{#rows as |row|}}
<tr>
{{#../cols as |col|}}
<td>{{row.COLUMNNAME}}</td>
{{/../cols}}
</tr>
{{/rows}}
In js this would be like row[index][col.name];
Any idea for solutions?
Found the answer, it's the lookup tag.
{{lookup row col.name}}
is equal to
row[col.name]
I am writing a phpunit test... on my page I have several rows, one of them is like this:
<tr><td>MATCH<small><span class="glyphicon glyphicon-pushpin"></span></small></td></tr>
Some are like this:
<tr><td>NOT A MATCH 1</td></tr>
<tr><td>NOT A MATCH 2</td></tr>
<tr><td>NOT A MATCH 3</td></tr>
how can I run a test to check that the row with the pushpin glyphicon is the one with "MATCH"?
Basically I want the test to confirm that the glyphicon is appearing on the correct row, and just having something like $crawler->filter('small:contains("' . $glyphCode . '")')->count() only confirms that the glyph exists - not that it's in the right place.
Any help appreciated, thank you.
You can use XPath Selectors with Symfony's DomCrawler.
To select your desired element use this XPath expression:
//td//small/span[#class="glyphicon glyphicon-pushpin"]
Then place it inside a PHPUnit assertion.
$this->assertEquals(1,
$crawler->filterXPath('//td//small/span[#class="glyphicon glyphicon-pushpin"]')->count()
);
I've used assertEquals 1 as expected value, to ensure that one element is found on the page.
Actually, the question can be treated as a string match problem.
There are several different ways to do that.
use PHP Simple HTML DOM Parser
$ret = $html->find('td[class=*glyph]');
use regular expression in PHP
the pattern string may like /class="[^"]+glyph/
run grep command in the shell
$ grep glyph xxx.php
I am trying to set a label in a gridview not to show a particular date if it is returned (it is because it is a default date and is not needed).
The code I have used is
<%# 'Convert.ToString(Eval("DateTaken")).Equals("01/01/1899") ? "" : Eval("DateTaken")'%>
Unfortunately, when I try and compile it the code won't run. I have tried to find an answer by research, but have not been able to do so.
It uses part of Chris's answer, but Equals does not work. Changing this to Contains does when parsing the value as year
<%# 'Convert.ToString(Eval("DateTaken")).Equals("01/01/1899") ? "" : Eval("DateTaken")'%>
This is not valid syntax as far as I am aware. You have single quotes ' wrapping your statement which is likely confusing the parser a lot. I'm not sure what you intend them to be doing but I'd suggest trying without:
<%# Convert.ToString(Eval("DateTaken")).Equals("01/01/1899") ? "" : Eval("DateTaken")%>
I can't test this but it looks like it should work.
Also for the comparison (I assumed you'd tested that elsewhere first) I suspect you may have problems with the fact that Convert.ToString likely includes a time element. Instead I would suggest specifying what string format you want to be outputted. Or even better assuming that it is a DateTime you are getting back compare it as a DateTime. Either of the following should work as a reliable comparison
(((DateTime)Eval("DateTaken")).ToString("yyyy-MM-dd")=="2014-03-05")
(((DateTime)Eval("DateTaken")).Date==new DateTime(2014,03,05))
I'm using Selenium IDE and I have a table where it has many rowns and columns. Each row has its own checkbox to select this row.
I was using this command to search for a specific row:
css=tr:contains('US Tester4') input[type="checkbox"]
But the problem is that in this colum, I have some other similar words like "US Tester41", "US Tester42" ... and when I use this command, it selects the wrong row.
I thought if I replace this word "contains" for some other like "equals" or "exactly" would work, but it didn't (I don't know the sintax).
Any ideas?
Follow the screenshot:
http://oi41.tinypic.com/2ake9hw.jpg
I'm not familiar with Selenium IDE, but with the selenium webdriver I would use an xpath. So I guess something like this will work for you:
xpath=//tr[td[3][text()='US Tester4']]//input[#type='checkbox']
This worked for me:
//tr//td[.='US Tester4']//input[type="checkbox"]
against:
<table>
<tr><td>US Tester</td>input(type="checkbox")</tr>
<tr><td>US Tester4</td>input(type="checkbox")</tr>
<tr><td>US Tester41</td>input(type="checkbox")</tr>
<tr><td>US Tester412</td>input(type="checkbox")</tr>
</table>
It matched the second element.
This worked for me
xpath=(//input[#name='uid'])[2])
The 2 being the order of elemets
I'm not very familiar with the IDE but I have used the Webdriver before. If possible I would use this xpath.
xpath = "//td[.= 'US Tester4']//previous-sibling::td//input[#type = 'checkbox']"
This should locate only one element on screen. Using previous-sibling and following-sibling is very helpful when you haven't got a good enough identifier on the exact element you want to find. In your case the which contains the checkbox hasn't a good identifier where as the after has text which you could match using the '=' operator. You just need to use the 'previous-sibling' to find the with the checkbox
I am beginning with QTP and just cannot find out how to get value of element. For example when I just want to compare the number of results found by google. I tried to select the element with object spy and use Val(Element) to assign the value into variable..but it doesnt work. Could anyone help with this? BTW, I am not sure whether selecting the text (element) to compare with Object spy is correct.
Thanks!
You should use GetROProperty in order to get the text and then parse it for the value.
Looking at a Google results page I see that the result is in a paragraph with id=resultStats in the 3rd bold tag.
<p id="resultStats"> Results <b>1</b> - <b>10</b> of about
<b>2,920,000</b>
for <b>qtp</b>. (<b>0.22</b> seconds)</p>
So the following script gets the number (as a string with commas).
Browser("micclass:=Browser")
.Page("micclass:=Page")
.WebElement("html id:=resultStats")
.WebElement("html tag:=b","index:=2").GetROProperty("innertext")