Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
44986 Lượt xem

I have seen a few similar questions on this but can't seem to find a solution. According to the XPath syntax here:

https://www.w3schools.com/xml/xpath_syntax.asp

An expression like this should match all buttons with name="action_rfq_send":

//button[@name='action_rfq_send']

However, the Odoo documentation for view inheritance says that the first node found from an xpath expression is the one selected:

http://www.odoo.com/documentation/10.0/reference/views.html#inheritance

Does this mean there is no way to select multiple nodes with one xpath expression in Odoo? If the view I'm extending has 3 buttons with name="action_rfq_send", is there any way to select them all with a single expression?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You cannot select all with a single xpath expression. You have to select one by one if more than one button with same name needs to referenced. Like:

<xpath expr="//button[@name='action_rfq_send'][1]" position="after">
</xpath>
<xpath expr="//button[@name='action_rfq_send'][2]" position="after">
</xpath>
Ảnh đại diện
Huỷ bỏ

odoo xpath nth

Câu trả lời hay nhất

I don't know how to do it with one expression, but you can do this:

<xpath expr="//form/group[1]" ...
<xpath expr="//form/group[2]" ...
<xpath expr="//form/group[3]" ...
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

In my case using numbers fails.

Just repeat the same expression as many times as you need:
<xpath expr="//button[@name='action_rfq_send']" position="after"></xpath>
<xpath expr="//button[@name='action_rfq_send']" position="after"></xpath>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You need to use parentheses around the xpath expression and from there use the index.


expr = "(//button[@name='action_rfq_send'])[1]"

expr = "(//button[@name='action_rfq_send'])[2]"

expr = "(//button[@name='action_rfq_send'])[3]"


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The Xpath code will be such as:

<xpath expr="//button[@name='action_rfq_send'][1]" ...............>

<xpath expr="//button[@name='action_rfq_send'][2]" ...............>

<xpath expr="//button[@name='action_rfq_send'][3]" ...............>

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 24
1751
3
thg 6 23
4613
2
thg 6 23
3588
3
thg 3 23
9387
1
thg 3 23
2162