Problem searching elements into a email list

Hi Pablo,

To start with the html in this app is aweful and is not making your life easy, especially with the

  • having the ng-if email’s address above it’s div in the parent div
  • and the ng-repeat email’s div being inside the ng-if email’s div

If you have access to the dev’s give them a hard time over it. Really that should be 2 defects on the html generatiion

The way I’d approach this is to break it down to parts. first I’d create some partial xpaths variables like this:

VAR    ${expected_email}    miguelpruebatest@yopmail.com
VAR    ${expected_subject}    Configura tu contraseña para

VAR    ${xp_basemsg}    //div[contains(@class, 'msglist-message')]
VAR    ${xp_ngif}    div[contains(@class, 'ng-binding')]
VAR    ${xp_ngrepeat}    div//div[contains(@class, 'ng-binding')]
VAR    ${xp_subject}    div/span[contains(@class, 'subject')]

Next use Get Element Count to get a count of messages that match ${xp_basemsg}

Then use a FOR-IN-RANGE loop to iterate over the messages and get the email addresses and subject

once you have them you can either append them to a list, add them to a dictionary or use an if statement to take action immediately, depends what you want, but I’ll show the if statement in this example:

${msgcount}=    Get Element Count    ${xp_basemsg}
FOR    ${index}    IN RANGE    ${msgcount}
    ${To_ngif}=    Get Text    (${xp_basemsg})[${index}]/${xp_ngif}
    ${To_ngrepeat}=    Get Text    (${xp_basemsg})[${index}]/${xp_ngrepeat}
    ${subject}=    Get Text    (${xp_basemsg})[${index}]/${xp_subject}
    IF    '${To_ngif}' == '${expected_email}' and '${subject}' == '${expected_subject}'
        # matched ngif email and subject
        # do somethng
        BREAK  # exit FOR loop 
    END
    IF    '${To_ngrepeat}' == '${expected_email}' and '${subject}' == '${expected_subject}'
        # matched ngrepeat email and subject
        # do somethng
        BREAK  # exit FOR loop 
    END
END

Hopefully that’s helpful,

Dave.

1 Like