Tal condition string contains - pyramid

Trying to change table data based on conditions.
<td tal:condition="string.stringname != '-shadow'"><strong>Stuff</strong></td>
<td tal:condition="string.stringname == '-shadow'"><em>Stuff</em></td>
string.stringname may have -shadow at the very end of the string, and it may not. I'm trying to get tal to display either table data based on whether one or the other is true. The page will need to display both cases, if both cases are met of course. tal:condition doesnt seem to be able to search if a string contains something, only if something is explicitly true or false.

Use str.endswith() to test if a string ends with a given substring:
<td tal:condition="not string.stringname.endswith('-shadow')"><strong>Stuff</strong></td>
<td tal:condition="string.stringname.endswith('-shadow')"><em>Stuff</em></td>

Related

Selecting a webpage radio-button

I am trying to do some webpage data extraction using VBA within excel. I have managed to automate the login process, which takes me to a new page with a search form. This form has an input field for 'Search Value' and a series of radio buttons that specify the variable to conduct the search on eg. ID number, Name. I am trying to automate filling in the input field and selecting one of the radio buttons and then submitting the form.
The code I used to login does not seem to work on the next page where I need to do the search. This is the HTML from the search page containing the input field:
<table width="100%">
<tr>
<td style="font-weight: bold; width:10%;" nowrap="nowrap">Search Value</td>
<td style="width: 15%; text-align: left;">
<input name="txtSearch" type="text" id="txtSearch" onkeyup="return txtSearch_onkeyup()" style="background-color:White;border-color:#222244;border-width:1px;border-style:Solid;height:20px;width:125px;" />
Which I try to fill in using:
ieDoc.Document.getElementsByName("txtSearch")(0).Value = "Test String"
Or:
ieDoc.Document.all.txtSearch.Value = "Test String"
Or
ieDoc.Document.getElementByID("txtSearch").Value = "Test String"
...all giving me the same Object defined error.
I have confirmed that the ieDoc is referencing the correct page after the login (by checking the title in the immediate window), and tried to ensure it is not a timing issue with page-loading.
I know the HTML methods in vba tend to be temperamental but I've run out of ideas. Any other way to access the input field on this page?
Success!
I was trying to reference an element on a sub-frame within the IE object, which I accessed with:
ieDoc.Document.frames(0).Document.all.txtSearch.Value = "Hello!"

Xpages - Repeat control with SSJS

I am building a history tracker, that continues to work with legacy code in non xpage apps. For xpage apps, I simply call the below function. This works fine:
function AddObjectivesHistoryItem(doc, dt, action, username){
var ArrDocHistory:array = doc.getItemValueArray("History");
if(ArrDocHistory.length < 1){
// This should always return an object as it is created when an objectives
document is first
// created but do this check to be safe and create an array if for some
reason it doesnt exist
ArrDocHistory = [dt+"|"+action+"|"+username];
}else{
// append new value to the array
ArrDocHistory.push(dt+"|"+action+"|"+username);
}
return ArrDocHistory;
}
The issue I have, is splitting and displaying the 3 data types. I have a 3 computed fields, which is date, username and status in a table within a repeat control, code, including first column and computed field below, this should be all values prior to the first pipe delimiter for each multi value.:
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Action</th>
<th>Username</th>
</tr>
</thead>
</table>
<table class="table table-hover">
<xp:repeat value="#{document1.History}" var="row">
<tbody>
<tr>
<td>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:var ArrDocHistory:array = document1.getItemValueArray("History");
print ("LEN: " + ArrDocHistory.length);
var test:array = new Array();
for (i=0; i<ArrDocHistory.length; i++){
var split = ArrDocHistory[i].split("|");
test.push(split[0]);
//return split[i]
}
return test}]]></xp:this.value>
</xp:text></td>
However, what this displays is all the values, in a line, seperated with a comma. For example, "value1, value2, value3" where as I expected, and need, and can't seem to be able to get each value to display on its own, in a new row. For example:
value1
value2
value3
I know I'm doing something silly, but am currently suffering from tunnel vision so any pointers greatly appreciated.
You are returning Test, to a single computed field. Change your repeat to return the array 'test', (it gets the value like you do, than split it to the array you have). Than the computed field returns one of the elements of test.
Put a page break after the computed field to see it the way you want.

Return value from an HTML class/scope?

I have a webpage that I'm trying to return a value from, however I can't find the right way to grab it with Selenium.
Here's the relevant HTML part:
<table class="table table-striped">
<tbody>
<tr class="hidden-sm hidden-xs">
<th scope="row"><a style="cursor: pointer"
onClick="document.formShip.P_IMO.value='9526942';document.formShip.submit();">
9526942</a>
</th>
I'm trying to get 9526942.
I've tried:
imo = driver.find_element_by_xpath("//*[contains(text(), 'document.formShip.P_IMO.value')]")
and looked around here, but don't know what element this is. I tried looking for the class hidden-sm hidden-xs, to no avail:
imo = driver.find_element_by_class_name('hidden-sm hidden-xs')
if you want to get the text you need to use .text. The .text method can be used with a webelement which some text in that.
in your first example which you tried, you are passing a different parameter with text(). usually when you use text(), you need to pass the value which is there between closing and open tags (the text which you see on the screen)
you simply try this.
imo = driver.find_element_by_xpath(.//tr[#class='hidden-sm hidden-xs']).text

Loop in table with Watir

Stuck with watir trying to create a loop to click in all the links included in a table. Currently the table has this format:
<table id="test">
<tbody><tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Link</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>http://facebook.com</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>http://google.com</td>
</tr>
</tbody></table>
And my current attempt looks like:
browser.table(:id => "test").rows do |tr|
tr.each do |td|
td.links.click
end
end
This code above does nothing in the browser & neither returns something in the terminal (no errors, no outputs).
Also tried a different approach using columns:
columns = browser.table(:id => "test").strings.transpose
browser.columns.each do |t|
t.click
browser.back
end
That outputs this error: jsfiddle.rb:24:in <main>': undefined methodcolumns' for # (NoMethodError)
The newer versions of Watir, version 6.0, automatically attempts to relocate stale elements. As a result, as long as the initial page does not change each time you reload it, you no longer need to save some sort of reference data before clicking the links.
It simply becomes:
my_table = browser.table(:id, 'test')
my_table.links.each do |link|
link.click
browser.back
end
This should work to click on each link in the table:
my_table = browser.table(:id, 'test')
table_links = my_table.links.map(&:text)
table_links.each do |link_text|
my_table.link(:text, link_text).click
browser.back
end
Largely based on Justin Ko's answer here.

suitescript set custom column value netsuite

Using Pick, Pack and Ship and advanced PDF HTML templates, NetSuite cannot display the qty remaining to pick. So if we do a partial pick, we cannot show the warehouse the remaining balance. The math is simple, here is the script and function I would like to see (based on forum feedback). Will this work and what is the best way to deploy this script such that the result is stored in the custom column until another pick takes place? The value is to be calculated at time of changes, but available to all related transaction records.
function SetQtytoPick(type){
if(type == 'item'){
var qtyordered = nlapiGetCurrentLineItemValue('item', 'quantity');
var qtypicked = nlapiGetCurrentLineItemValue('item', 'quantitypicked');
var qtytopick = qtyordered-qtypicked
nlapiSetCurrentLineItemValue('item', 'custcol_qty_to_pick', qtytopick);
}
}
Actually one of the really fun things about the Advanced HTML/PDF templates is that you don't need your code. When print the packing slip the template supplies the item fulfillment (as record) and the sales order (as salesorder).
You can get the value you need from the Sales Order's Item Line's quantityfulfilled value.
the following snippet was from a customized packing slip where the customer wanted the PS to always show all the Sales Order's items. It doesn't directly solve your problem but you can see that the template itself can be used to calculate the items remaining to ship at the time of printing.
<#list salesorder.item as tranline>
<#assign shipped=0>
<#assign prevShipped=tranline.quantityfulfilled>
<#assign qtyRemaining=tranline.quantity - prevShipped>
<#if (tranline.quantitybackordered gt 0)> <#assign qtyRemaining=tranline.quantitybackordered></#if>
<#list record.item as item><#if tranline.line==item.orderline>
<#assign shipped=item.quantity>
<#assign prevShipped=tranline.quantityfulfilled-item.quantity>
</#if></#list>
<tr>
<td colspan="12"><span class="itemname">${tranline.item}</span><#if tranline.itemtype =='NonInvtPart'>**<#assign anyNonInvt='T'></#if><br />${tranline.description?html}</td>
<td align="center" colspan="3"><#if shipped gt 0><b>${shipped}</b><#else>0</#if></td>
<td align="center" colspan="3">${tranline.quantity}</td>
<td align="center" colspan="3">${prevShipped}</td>
<td align="center" colspan="3">${qtyRemaining}</td>
<td colspan="4">${tranline.options?html}</td>
</tr>
</#list>
</#if>
The other way to do this would be to put your script into a user event script before submit event. You'd deploy it on Item Fulfillments

Resources