İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
6367 Görünümler

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
Vazgeç

Would you please add more details?

Üretici En İyi Yanıt

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
Vazgeç

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

Üretici

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);

Üretici

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

En İyi Yanıt

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

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
May 23
2799
0
Ağu 21
2544
2
Eyl 23
10454
1
May 23
3222
1
Şub 22
7758