Using Dynamic Variables in Velocity Templates - velocity

I am using velocity templates to generate email templates and here I want to create tables for each 'tag' with respective values as table data.
I am passing a List tags with details of the tags including tagName, using which I am passing the respective List for each tag. (If tagName = "test", I am passing the data for the test table as $test)
As shown I have set the data of each table to $arrayobjs, but the table does not display the rows as I think it doesnt iterate through the $arrayobs. Please help me iterate through the data and set the data to the coloumns.
P.S.-Although I am able to print the value of $tags[0]
, $arrayobjs[0] does not print a value
#set ($d = '$')
#foreach($tag in $tags)
#set ($var = "${d}${tag.tagName}")
#set ($arrayobjs = "#evaluate($var)")
<table style='width:600px; padding-left: 11px; font:Segoe UI;'>
<tr>
<td> <span style='font-size: 17px; font-weight: 400; font-family:Georgia;'>$tag.tagName </span></td>
</tr>
</table>
<br>
<table width=583 style='width:437.5pt; margin-left:8.25pt;border-collapse:collapse;font-family:"Segoe UI",sans-serif;'>
<tr style='vertical-align:top;height:10px;'>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c;'><b>COL1</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=100px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL2</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL3</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL4</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL5</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
<td width=50px style='border:solid white 1.0pt;background: #a3a3c2;padding:1pt 1pt 1pt 1pt;'>
<p> <span style='font-size:10.0pt;color:#3d3d5c'><b>COL6</b></span> <span style='font-size:9.0pt;color:#404040'> <br><b></b> </span> </p>
</td>
</tr>
#foreach($o in $arrayobjs)
<tr style='vertical-align:top;height:5px;'>
<td width=50px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col1 </span> </p>
</td>
<td width=180px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col2</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col3</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col4</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col5</span> </p>
</td>
<td width=30px style='border:solid white 1.0pt;background: #f0f0f5;padding:0.5pt 0.5pt 0.5pt 0.5pt;'>
<p> <span style='font-size:9.0pt;color:#7F7F7F'></span> <span style='font-size:9.0pt;color:#404040'>$o.col6</span> </p>
</td>
</tr>
#end
</table>
#end

After almost 2 years I suggest the following answer :-)
#set ($d = '$')
#set ($h = '#')
#foreach($tag in $tags)
#set ( $temp = "${h}set ( ${d}var = ${d}${tag.tagName} )" )
#evaluate($temp)
## html code for table header
#foreach($o in $var)
## table rows
#end
#end

Related

Odoo - Move invoice total at the bottom

I created a custom invoice but how can I add make the payment terms and total row at the bottom on the page? (see image for desired scenario)
<div class="clearfix" style="line-height:0">
<p t-if="o.narration" name="comment">
<span t-field="o.narration"/>
</p>
<p t-if="o.invoice_payment_term_id" name="payment_term" style="font-size:12px;margin-left:-120px;text-transform:uppercase;line-height:0">
Payment <b><span t-field="o.invoice_payment_term_id"/></b> after statement of accounts
<!--<span t-field="o.invoice_payment_term_id.note"/>-->
</p>
<p t-if="o.amount_total" style="font-size:12px;margin-left:-120px;text-transform:uppercase;line-height:normal">
<span t-esc="o.compute_amount_in_word(o.amount_total)"/>
</p>
<div id="total" class="row" style="margin-top:-30px !important;">
<div t-attf-class="#{'col-6' if report_type != 'html' else 'col-sm-7 col-md-6'} ml-auto">
<table class="table table-sm table-borderless" style="page-break-inside: avoid; width:222px; margin-left:235px !important;border-bottom: 4px solid white">
<tr>
<td class="text-right"><strong>TOTAL</strong></td>
<td style="" class="text-right">
<span class="text-nowrap text-right" style="" t-field="o.amount_total"/>
</td>
</tr>
</table>
</div>
</div>
</div>
Right now it's showing payment terms, amount in words, and total just below where the table ends. I tried to make the position: relative, but then it shows only on the first page and will overlap if the invoice is more than one page. (see image)

Not able to check the check box, exception "element not visible"

In an table which can contain more rows, user is searchable using the email id. After searching, selecting the first check box. But selenium is throwing the element not visible exception.
//*[#id='share_user']/tbody/tr1/td1//label
//*[#id='share_user']/tbody/tr1/td1//input
//label[#for='checkbox_416']
last identifier is dynamic. Still getting the element not visible exception.
Table code is mentioned below
<table class="table table-striped table-hover dataTable" id="share_user"
aria-describedby="share_user_info">
<thead>
<tr role="row">
<th class="small-cell sorting" role="columnheader" tabindex="0"
aria-controls="share_user" rowspan="1" colspan="1" style="width: 137px;"
aria-label="Share Profile : activate to sort column ascending">Share Profile </th>
<th class="medium-cell sorting" role="columnheader" tabindex="0"
aria-controls="share_user" rowspan="1" colspan="1" style="width: 523px;"
aria-label="User Details: activate to sort column ascending">User Details</th>
<th class="medium-cell sorting_asc" role="columnheader" tabindex="0"
aria-controls="share_user" rowspan="1" colspan="1" style="width: 366px;"
aria-sort="ascending" aria-label="Access: activate to sort column descending">Access</th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<td class="">
<div class="checkbox check-default">
<input name="checkUser" id="checkbox_416" value="416" class="shareCheck"
type="checkbox">
<label for="checkbox_416"></label>
</div>
</td>
<td class=" ">
<img src="" class="img-responsive display-inline share-image">
<div class="display-inline">
<p class="share-name">alexx</p>
<p class="muted">
<i class="fa fa-envelope" hidden="true"></i>
<span>alexxm360#gmail.com</span>
</p>
</div>
</td>
<td style="vertical-align: middle;" class=" sorting_1">
<div class="select2-container medium-cell" id="s2id_rolelink416"
style="float:left;">
<a href="javascript:void(0)" onclick="return false;" class="select2-choice"
tabindex="-1">
<span class="select2-chosen">PROFILE ADMIN</span>
<abbr class="select2-search-choice-close"></abbr>
<span class="select2-arrow">
<b></b>
</span>
</a>
<input class="select2-focusser select2-offscreen" id="s2id_autogen11"
type="text">
<div class="select2-drop select2-display-none select2-with-searchbox">
<div class="select2-search">
<input autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" class="select2-input"
type="text">
</div>
<ul class="select2-results">
</ul>
</div>
</div>
<select name="profileUsers.roleId" id="rolelink416"
class="medium-cell select2-offscreen" style="float:left;" tabindex="-1">
<option value="6">PROFILE ADMIN</option>
<option value="7">PROFILE AGENT</option>
<option value="8">PROFILE VIEWER</option>
<option value="196">profile role</option>
</select>
</td>
</tr>
</tbody>
</table>
providing the screen shots as well.
Try to use explicit wait with Expected Conditions
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement checkbox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='share_user']/tbody/tr[1]/td[1]//input")));
checkbox.click();
You can use the following expression, I have verified working fine.
driver.findElement(By.xpath("//*[#id='share_user']/tbody/tr[1]/td[1]/div")).click();
Try this
int ele_size=driver.findElements(By.xpath("locator")).size();
driver.findElements(By.xpath("locator")).get(ele_size-1).click();
We might encounter element not visible exception if element matching the locator existed in the DOM but is not currently visible. So we have to take the size of the element in first statement then in next statement we have to take the first element from the list and click on element.
Used this //*[#id='share_user']/tbody/tr[1]/td[1]/div worked

XPath: Get previous item, filtering by class

I have this HTML:
<div class="DivHeaderSizes" data-subgroup="1">
<img style="display:none" class="help-size-img-colorbox" data-subgroup="1_Man" src="Man.gif">
<div class="subgroup-description">Jogging</div>
<div class="help-size-link cboxElement" data-subgroup="1_Man">Tutorial</div>
</div>
<div style="float: left;" class="DivSizeElement">
<table data-size="41" class="SizeElement" style="display: none;">
<tbody>
<tr>
<td class="td-label-size">
<span class="label-size" data-size="41">41</span>
</td>
<td class="td-label-textbox">
<input name="ctl00$CthBody$sizelist$TxtSize_41" type="text" maxlength="4" id="CthBody_sizelist_TxtSize_41" class="txt-Size" data-price="19.50" data-size="41" data-available="0" data-subgroup="1" style="width:30px;">
</td>
</tr>
</tbody>
</table>
</div>
<div style="float: left;" class="DivSizeElement">
<table data-size="42" class="SizeElement" style="display: none;">
<tbody>
<tr>
<td class="td-label-size">
<span class="label-size" data-size="42">42</span>
</td>
<td class="td-label-textbox">
<input name="ctl00$CthBody$sizelist$TxtSize_S" type="text" maxlength="4" id="CthBody_sizelist_TxtSize_S" class="txt-Size" data-price="19.50" data-size="42" data-available="0" data-subgroup="1" style="width:30px;">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Using Selenium with C# and starting from input element with name
ctl00$CthBody$sizelist$TxtSize_41
I want the XPath expression to get the text "Jogging". Thanks.
If the context node is input[#name='ctl00$CthBody$sizelist$TxtSize_41'], then the following XPath will select the div containing "Jogging":
(preceding::div[#class='subgroup-description'])[1]
Or you could use:
ancestor::div[1]/preceding-sibling::div[1]/div[#class='subgroup-description']

How can I Selecting Kendo Drop Down using xpath

I have the following HTML:
<table class="w98">
<tbody>
<tr>
<tr>
<tr>
<td class="p-controlSetLabel">
<td class="editor-field">
**<span class="k-widget k-dropdown k-header" style="width: 165px;" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="VatRateId_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="304dd433-4a68-458b-a6d6-03b72335f1cb">**
<span class="k-dropdown-wrap k-state-default" unselectable="on">
<span class="k-input" unselectable="on">Standard - Standard</span>
<span class="k-select" unselectable="on">
<span class="k-icon k-i-arrow-s" unselectable="on">select</span>
</span>
</span>
<input id="VatRateId" class="k-valid" type="text" value="d20b" style="width: 165px; display: none;" name="VatRateId" data-val-required="Please select a VAT Rate." data-val="true" data-role="dropdownlist">
The input id="VatRateId" is hidden, so I can't access it.
My current solution is the following:
var allDropDownFields = FindElements(By.XPath(".//*[#class='k-dropdown-wrap k-state-default']") -- This will return a list of all drop down fields
Then I loop each one of them to find the correct drop down field I want.
Is there a better way of finding the element without getting a list, I tried the following:
FindElement(By.XPath(".//*[#class='k-dropdown-wrap k-state-default'and #aria-owns = 'VatRateId_listbox']")
and the above code is not work.
HTML code is as below:-
<span class="k-widget k-dropdown k-header" style="width: 165px;" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="VatRateId_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="304dd433-4a68-458b-a6d6-03b72335f1cb">* <span class="k-dropdown-wrap k-state-default" unselectable="on"> <span class="k-input" unselectable="on">Standard - Standard</span>
Any better suggestion?

Assistance with a dynamically generated field

I have another dynamic question for you. I have three input fields that I need to enter values for. These "dijit_form_DateTextBox_36" are created dynamically (the 36 is variable). There is a value earlier in the code that is unique and can be searched for. I know I need to use something like:
driver.findElement(By.xpath("//div[contains(., 'QA GM 04012014 1424 Item Name')]/parent::...somepath.sendKeys("...");
But I am still too new to this stuff to be able to figure it out. And if someone can assist me with what I need to put, as well as how they figured it out, I would greatly appreciate it. I'd really love to solve these on my own! Code is below. Bolded portion is the static text that can be searched. Bolded and italicized lines are the three controls that need to be modified. NOTE: The id="shipDate0_0" is also dynamic, it can be shipDate0_0, shipDate1_0, etc. So can't key on that.
<tr class="tableControlHeader twTableHeaderTR"></tr>
<tr class="tableControlDataRow evenRow twTableTR">
<td class="twTableTD details" align="center" rowspan="2"></td>
<td class="twTableTD details" align="center" rowspan="2">
<p>
<b>
QA GM 04012014 1424 Item Name
</b>
</p>
<br></br>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
</td>
<td class="twTableTD" align="center" rowspan="2"></td>
<td class="twTableTD" align="center"></td>
<td class="twTableTD" align="center"></td>
<td id="shipDate0_0" class="twTableTD" align="center">
<div style="padding-right: 20px;">
<div id="dateWrap-projectedFirstShipDate_0_0" class="inputText_Full twControl twDateSelector" ;="" onblur="updateAvgPerWeek(0,0)" initialvalue="" value="" name="tw#local#quoteComparison#0#country#0#projectedFirstShipDate" style="white-space:nowrap;">
<div id="projectedFirstShipDate_0_0" lang="" dojoattachpoint="pickerDiv" widgetid="projectedFirstShipDate_0_0" name="tw#local#quoteComparison#0#country#0#projectedFirstShipDate">
<span dojoattachpoint="leftPicker">
<div id="widget_dijit_form_DateTextBox_36" class="dijit dijitReset dijitInlineTable dijitLeft dateSelectionSin…tBox dijitComboBox dijitDateTextBox dijitComboBoxOpenOnClick" role="combobox" widgetid="dijit_form_DateTextBox_36">
<div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" role="presentation" dojoattachpoint="_buttonNode, _popupStateNode" popupactive="true"></div>
<div class="dijitReset dijitValidationContainer"></div>
<div class="dijitReset dijitInputField dijitInputContainer">
<input id="dijit_form_DateTextBox_36" class="dijitReset dijitInputInner" type="text" aria-haspopup="true" role="textbox" dojoattachpoint="textbox,focusNode" autocomplete="off" aria-valuenow="null" aria-invalid="false" tabindex="0" value="" style="" delocalized="null" aria-disabled="false"></input>
<input type="hidden" value=""></input>
</div>
</div>
</span>
<span dojoattachpoint="rightPicker"></span>
<span style="position: absolute;" dojoattachpoint="calImage"></span>
<input id="projectedFirstShipDate_0_0" type="text" isdatefield="true" name="tw#local#quoteComparison#0#country#0#projectedFirstShipDate" style="display:none" dojoattachpoint="hiddenInput" delocalized="null"></input>
</div>
</div>
</div>
</td>
<td id="InDate0_0" class="twTableTD" align="center" ;="" onclick="updateAvgPerWeek(0,0)">
<div style="padding-right: 20px;">
<div id="dateWrap-inDate_0_0" class="inputText_Full twControl twDateSelector" ;="" onblur="updateAvgPerWeek(0,0)" initialvalue="" value="" name="tw#local#quoteComparison#0#country#0#inDate" style="white-space:nowrap;">
<div id="inDate_0_0" lang="" dojoattachpoint="pickerDiv" widgetid="inDate_0_0" name="tw#local#quoteComparison#0#country#0#inDate">
<span dojoattachpoint="leftPicker">
<div id="widget_dijit_form_DateTextBox_35" class="dijit dijitReset dijitInlineTable dijitLeft dateSelectionSin…tBox dijitComboBox dijitDateTextBox dijitComboBoxOpenOnClick" role="combobox" widgetid="dijit_form_DateTextBox_35">
<div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" role="presentation" dojoattachpoint="_buttonNode, _popupStateNode" popupactive="true"></div>
<div class="dijitReset dijitValidationContainer"></div>
<div class="dijitReset dijitInputField dijitInputContainer">
<input id="dijit_form_DateTextBox_35" class="dijitReset dijitInputInner" type="text" aria-haspopup="true" role="textbox" dojoattachpoint="textbox,focusNode" autocomplete="off" aria-valuenow="null" aria-invalid="false" tabindex="0" value="" style="" delocalized="null" aria-disabled="false"></input>
<input type="hidden" value=""></input>
</div>
</div>
</span>
<span dojoattachpoint="rightPicker"></span>
<span style="position: absolute;" dojoattachpoint="calImage"></span>
<input id="inDate_0_0" type="text" isdatefield="true" name="tw#local#quoteComparison#0#country#0#inDate" style="display:none" dojoattachpoint="hiddenInput" delocalized="null"></input>
</div>
</div>
</div>
</td>
<td id="OutDate0_0" class="twTableTD" align="center" onclick="updateAvgPerWeek(0,0)">
<div style="padding-right: 20px;">
<div id="dateWrap-outDate_0_0" class="inputText_Full twControl twDateSelector" ;="" onblur="updateAvgPerWeek(0,0)" initialvalue="" value="" name="tw#local#quoteComparison#0#country#0#outDate" style="white-space:nowrap;">
<div id="outDate_0_0" lang="" dojoattachpoint="pickerDiv" widgetid="outDate_0_0" name="tw#local#quoteComparison#0#country#0#outDate">
<span dojoattachpoint="leftPicker">
<div id="widget_dijit_form_DateTextBox_34" class="dijit dijitReset dijitInlineTable dijitLeft dateSelectionSin…tBox dijitComboBox dijitDateTextBox dijitComboBoxOpenOnClick" role="combobox" widgetid="dijit_form_DateTextBox_34">
<div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" role="presentation" dojoattachpoint="_buttonNode, _popupStateNode" popupactive="true"></div>
<div class="dijitReset dijitValidationContainer"></div>
<div class="dijitReset dijitInputField dijitInputContainer">
<input id="dijit_form_DateTextBox_34" class="dijitReset dijitInputInner" type="text" aria-haspopup="true" role="textbox" dojoattachpoint="textbox,focusNode" autocomplete="off" aria-valuenow="null" aria-invalid="false" tabindex="0" value="" style="" delocalized="null" aria-disabled="false"></input>
<input type="hidden" value=""></input>
</div>
</div>
</span>
<span dojoattachpoint="rightPicker"></span>
<span style="position: absolute;" dojoattachpoint="calImage"></span>
<input id="outDate_0_0" type="text" isdatefield="true" name="tw#local#quoteComparison#0#country#0#outDate" style="display:none" dojoattachpoint="hiddenInput" delocalized="null"></input>
</div>
</div>
</div>
</td>
<td id="BuyQuantity0_0" class="twTableTD" align="center" onblur="updateAvgPerWeek(0,0)" name="BuyQuantity0"></td>
<td id="TotalCost0_0" class="twTableTD" align="center" name="TotalCost0"></td>
<td id="NumberOfWarehouses0_0" class="twTableTD" align="center" onblur="updateAvgPerWeek(0,0)" td=""></td>
<!--
# of Warehouses
-->
<td id="AveragePerWarehouse0_0" class="twTableTD" align="center" name="AvgPerWhouseWeek0"></td>
<!--
Cost per Warehouse
-->`enter code here`
<td id="ProjectedSellPrice0_0" class="twTableTD" align="center" td=""></td>
<!--
Projected Sell Price
-->
<td id="PercentOfTotal0_0" class="twTableTD" align="center"></td>
<td class="twTableTD" align="center" rowspan="2"></td>
</tr>
The best xpath I am able to come up with is this:
//td[normalize-space()='QA GM 04012014 1424 Item Name']/following-sibling::td[contains(#id, 'shipDate')]//input[contains(#class,'dijitInputInner')]
Let me explain:
This part finds the td element with the text you're looking for, the normalize-space() call is just like text(), but trims any whitespace before/after the text & I've found it to be invaluable since discovering it a short time ago. text() will return whitespace and is often difficult to match
//td[normalize-space()='QA GM 04012014 1424 Item Name']
This next part finds ALL td's after the previous element. From the code snippet provided this will find ALL 13 td's that follow
/following-sibling::td
Narrow down that set of 13 by finding only the td containing the ID you're interested in, this is better than using a hardcoded number like /following-sibling::td[2] to find the second td
/following-sibling::td[contains(#id, 'shipDate')]
Then find the input field that you're interested in, there are number of ways you could do this, choose whichever you prefer
//input[contains(#class,'dijitInputInner')]
//input[contains(#id,'dijit_form_DateTextBox')]
I hope that's clear enough & works well for you, please let me know if not