Skip to Content
Menu
This question has been flagged
3 Replies
5321 Views

When we inspect the Odoo field , we can see the HTML id of that. But it is changing from time to time. Is there any method to set that HTML id a constant ? Following is an example how it appears.

<label for="o_field_input_27" class="o_form_label c_label-9" style="width:30% !important;">
Phone
</label>

<input class="o_form_input c_field-63 o_form_field" id="o_field_input_27" type="text" style="width:25% !important;margin-right:7% !important">


Avatar
Discard

Would you please add more details?

Author Best Answer

I am doing selenium automated testing ,for that I want to identify the  elements using its id . If i want to find elements like below then I can find that elements only using id . I don't want to find elements by xpath, since xpath can be changed when new fields are added. And also i would like to select elements without using class because there are some elements with same class.

<input class="o_form_input c_field-63 o_form_field" id="o_field_input_27" type="text" style="width:25% !important;margin-right:7% !important">

Avatar
Discard

In this case, you have two options

1) Add a unique class on each field you want to select during selenium test

<field name="partner_id" class="selenium_partner"/>

2) Patch the rendering engine and add new html `name` attribute on each field same as the field name

Note: The second option will break when form view has one2many field with an editable tree view and both contain same field name

Author

In first option, They already have classes, so cannot create another class for the same field.

<field name="company_id" class="c_field-65" required="1" options='{"no_open": True,"no_create":True }'/>

Can you please explain the second option in more detail please?

for the first option, if you add class from xml it will append the class so even though there is already existing class

anyway for the second option,

Form view rendered set unique label through `setIDForLabel` of abstract field

so in abstract file /addons/web/static/src/js/fields/abstract_field.js

add below line in `setIDForLabel` function

this.getFocusableElement().attr('name', this.name);

Author

Thanks Ravi Gadhia , Adding a new class helps (Y). Thanks alot for your Answer !!!!

Best Answer

No, you can't it added by form view rendering engine.
what's your purpose to make id constant?

Avatar
Discard
Related Posts Replies Views Activity
1
May 23
1158
0
Aug 21
1268
2
Sep 23
8062
1
May 23
1577
1
Feb 22
4742