how to set name of multiple textbox in openerp using qweb template engine? - odoo

Here is my code:
<tr t-foreach="keyword" t-as="item"><td><t t-esc="item_value"/></td><td><input type="text" name=""/></td></tr>
So here, Textbox are generated dynamically.
Now I want to set textbox name to the value that is generated on
<t t-esc="item_value"/>

To set the text box name to item_value you need to use the t-att attribute:
<input type="text" t-att-name="item_value"/>
Hope this helps!

Related

Xpath for Submit button with precedence nodes select file and *

Query 1:
I would request you to please help me on getting xpath for submit button. Absolute path starts with Select file and *.
<div id="bg">
<label id="label" style=" font-family: Segoe UI;color:#2e2e2e; font-size:12px; float:left; padding-top:8px;">
Select File <span id="spanhide" class="red">*</span></label>
<div style="margin-left:105px;"><input type="file" name="filUploadIcon" id="filUploadIcon" class="txt-box" onchange="FileUpload_OnChange(this,event);" style="width:180px;">
<input type="submit" name="btnUploadcancel" value="" onclick="return check();" id="btnUploadcancel" title="Upload" class="upload_pop"></div>
<input name="textFileName" type="text" id="textFileName" style="display:none;">
<input type="hidden" name="hdnframeID" id="hdnframeID">
<input type="hidden" name="hdnlbl" id="hdnlbl">
</div>
Query 2:
How to write xpath to skip few nodes in between. Please help. Also let me know adding // or * in between to skip nodes.
Ex: Above HTML
//*div[#id="bg"]/skip elements before input type submit node/input [#type="submit"]
Use the below xpath to target the precedence nodes that include the label with the string "Select File" and the embedded span that contains '*'.
//div[contains(#id, 'bg')]/label[contains(text(), 'Select File')]/span[contains(text(), '*')]
Then add on the below line to return to the parent node label to the span tag.
/parent::label
Then add on the below to get to the sibling div tag of the label tag, which contains the input tag with a type of submit.
/following-sibling::div/input[#type='submit']
So the xpath in its entirety should look like this:
//div[contains(#id, 'bg')]/label[contains(text(), 'Select File')]/span[contains(text(), '*')]/parent::label/following-sibling::div/input[#type='submit']
You can use below xpath.
//div[#id='bg']//input[#name='btnUploadcancel']
Strongly suggest to go through this to learn more on xpath 1.0 which will answer all your questions in OP.

How to Select a checbox by its corresponding label name

I am relatively new to xpath and I'm having an issue with Selecting a checkbox.
The following expression works fine
:xpath=//div/label[#for='chkCat2']
But I need to select a checkbox based on its label name (Music in this case)
Unfortunately, this -
xpath=.//div[label[contains(text(),'Music')]
is clicking on the label, not on the checkbox.
How is it possible to do that? I also tried this one but its not able to locate the element:
xpath=.//div[label[contains(text(),'Music')]/preceding-sibling::label]
That's the sample of the code:
<input name="ctl00$cphContent$ThreeMedia$categoriesRepeater$ctl01$ctl00"
data-bind="attr:{'id': 'chkCat' + id, 'data-id': id}, checked: selected" id="chkCat2" data-id="2" type="checkbox">
<label data-bind="attr:{'for': 'chkCat' + id}" for="chkCat2" class=" firepath-matching-node"></label>
<label class="chkbox-content margin-bottom-0" data-bind="text: name">Music</label>
Thanks for the help
But I need to select a checkbox based on its label name (Music in this case)
Assuming div is the parent element of the provided checkbox element, try using below xpath :-
.//div[normalize-space(.)='Music']/input
or more specific
.//div[normalize-space(.)='Music']/input[#type='checkbox']
one more
.//div[label[text() = 'Music']]/input
Try this below mentioned xpath
//label[text()= 'Music']/..//preceding-sibling::input[#id='chkCat2']
Explanation of xpath:- Use text method along with <label> tag and move ahead with <input> tag using preceding-sibling keyword.

TestStack.Seleno TickCheckbox not working

I have 2 forms that I am testing using TestStack.Seleno. Both forms have a checkbox that is mandatory. The first form has (including the checkbox) 5 fields. I can use TestStack.Seleno to create a passing test with valid data. I set the checkbox like this:
Input.TickCheckbox(f=>f.Accept,form.Accept);
On my other form which has 10 or so fields, when I try to set the checkbox to be ticked (using the same code) nothing happens. However when I try
var acceptCheckBox = Find.Element(By.Name("Accept"),new TimeSpan(0,0,0,50));
if (form.Accept)
{
acceptCheckBox.Click();
}
I get error "Element is not currently visible and so may not be interacted with"
Element is clearly visible and is not injected in using javascript.
I am using latest version of TestStack.Seleno from github.
Any ideas?
So I have managed to figure out what the issue is and have a work around, however I cannot explain why it works on the other form. The mandatory Accept field has html generated by mvc that looks like
<div>
<input class="check-box" data-val="true" data-val-mustbetrue="The Accept our field is required" data-val-required="The Accept our field is required." id="Accept" name="Accept" type="checkbox" value="true"><input name="Accept" type="hidden" value="false">
<label for="Accept">
Accept our Please accept our Terms and Conditions
</label>
<span class="field-validation-valid" data-valmsg-for="Accept" data-valmsg-replace="true"></span>
</div>
So you have the checkbox and hidden field both with id Accept, I suspect in code seleno is picking up the hidden field and setting value, so I updated my code todo
var acceptCheckBox = Find.Element(By.CssSelector("#Accept.check-box"));
acceptCheckBox.Click();
Now everything works.
Ismail

How do I get text from web brwoser into a label in vb?

How do I get this, from my webbrowser into a label in vb?
Like.. how do do I get the "apple" into a label?
<div class="banana">
<input class="form-control" type="text" placeholder="Result" value="apple>
</div>
Try the following:
YourLabel.Text = Wb.Document.GetElementById("yourId").GetAttribute("value")
You'll have to provide the input tag in the HTML document with an id, though. If you're not in control of the HTML, take a look at GetElementsByTagName.

Variable number of fields in form using struts 1.X

I need to build a form that loads a table that in each row contains a checkbox and an input text (the number of rows is variable, because it's loaded from a db). So my questions are:
What fields should the associate formbean have ? ArrayLists ? One HashMap ?
How can I know (once the form is submitted) what checkbox was selected so I consider the corresponding input text ?
I'm using struts 1.X as framework.
Thanks in advance!
Personally, I would use an array (list) for the checkboxes and a map for the input texts. You have to consider the fact that checkboxes are not sent on the request if they are not selected, but all your input texts are always sent. So, match the value of a checkbox with the map parameter of an input text, something like:
<input type="checkbox" name="ckName" value="val1" ../>
<input type="text" name="mapMethod(val1)" ../>
<input type="checkbox" name="ckName" value="val2" ../>
<input type="text" name="mapMethod(val2)" ../>
<input type="checkbox" name="ckName" value="val3" ../>
<input type="text" name="mapMethod(val3)" ../>
...
This means you will always have a map with all values:
val1 = "textbox 1 value"
val2 = "textbox 2 value"
val3 = "textbox 3 value"
...
and also have a list of selected checkboxes which can be:
[val1]
[val1, val2]
[val1, val2, val3]
... different combinations or []
You then keep the textbox values from the map only for the keys that are found in your list of checkbox values.
P.S. Remember also to reset your checkboxes.