Searching element that are at a different xpath level

Hi,

It seems in your examples above that you fix some indices, and not going through the correct nodes.

First this:

Set Variable    ${Con_check}    (//div[@id='flight-card'])[1]//input[@type='radio' and @checked]

Will stop at the first “flight-card” div, then may indeed return several input located below. But it has no text associated below (green area in your screen). The text you need is in a following-sibling of the input’s div parent.

Then in your first Get Element Count and FOR loop, you overwrite ${nombre} at each loop, so you will always get the last, or same name (as previously you fixed to the first). You should either name the variable in a incremental way, or add it to a list.

In your second case, you Get Webelements which returns a list, but then you loop and reevaluate it in the loop, and use Get Text on a fixed variable. The point here is to extract text from ${element}.

To my point of view, you should (to adjust of course), use the correct xpath variable to aim the text in the div (verify in inspector that it highlights the correct ones).
I would say something like this :

     VAR    ${Con_check}    //div[@id='flight-card']//input[@type='radio' and @checked]/following::div[@data-qa='company-name'][1]//div
     ${Elements_with_checked}    Get WebElements    ${Con_check}

     VAR     ${i}     1
     FOR    ${element}    IN    @{Elements_with_checked}
         ${cia_name${i}}    Get Text    ${element}
         ${i}     Evaluate     ${i} + 1
    END

==> Here we search for every flight card id, with an input radio and checked, then the first following div company-name, and finally the div containing the text.
Then you get webelements and loop on it by taking are of not overwriting the variables (incrementing the name).

Regards
Charlie

2 Likes