Atrofio
Atrofio

Reputation: 1

How to Select a Dynamically Generated Dropdown Item in an Odoo12 Tour Test Using JavaScript?

I've been working on a custom Odoo12 tour test, and I’m running into an issue with selecting items from a dynamically-generated dropdown. Here’s a breakdown of the steps I'm trying to implement:

  1. In a form, the tour clicks on a line called "Add a product." This opens a new modal with another form.
  2. In this other form, a product ID or a related identifier is entered in the product name box. This triggers a dropdown with matching product suggestions based on the entered query.
  3. The idea is to click on the first product in the dropdown (it’s the only match based on the input provided).
  4. Finally, the tour clicks "Save" on this second modal.

The problem comes with the Step 3: the dropdown items seem to have dynamically changing IDs (e.g., #o_field_input_170, #o_field_input_167, etc.), so I can’t target a specific ID.

Here’s what I’ve tried to solve it:

Here's the code example with the Key event:

tour.register('test2_tour', {
        test: true,
        url: "/web",
        wait_for: base.ready(),
    }, [

        // previous steps...

        {
            content: "Click on Add a product",
            trigger: 'a:contains("Add a product")',
        },
        {
            content: "Set product code",
            trigger: '#o_field_input_875',
            run: 'text 167020',
        },
        {
            content: "Select the product",
            trigger: '#o_field_input_875',
            run: 'keydown 13',
        },
        {
            content: "Confirm the product",
            trigger: '.modal-footer > .btn:nth-child(1) > span',
        },
    ]);

The CSS selector of the dropdown is the following: .o_form_nosheet > div:nth-child(3) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > div:nth-child(1) > div:nth-child(1)

HTML Inspection of the box

Has anyone faced a similar issue, or does anyone have a reliable approach to wait for and select a dynamically generated dropdown item in an Odoo tour test?

There's not much documentation, specially for Odoo12 for this topic, so any extra documentation that may be usefu

Thanks in advance for any help!

Upvotes: 0

Views: 40

Answers (1)

Ahrimann Steiner
Ahrimann Steiner

Reputation: 1314

It seems that there is not problem with this kind of css selector because it is used in official addons too (addons website_slides > slides_tour.js):

{
    trigger: 'iframe li.breadcrumb-item:nth-child(2)',
    content: Markup(_t("Click on your <b>Course</b> to go back to the table of content.")),
    position: 'top',
}

How about using div name=product_id to select the parent of your nth-child?

Is the problem maybe due to the fact that the modal content does not exist yet when performing your test ?

For instance, in skils_tour.js:


    {
        content: "Save it",
        trigger: ".o_form_button_save",
        in_modal: true,
        run: "click",
    },


Upvotes: 0

Related Questions