How do I get table column contents, then click a dropdown (li)not in list?

I have a page that adds items to a table, but entries for the third row cannot be duplicated, so I need to get all of the 3rd column text in the table (as a list I assume), and then click the add button and a dropdown li to add a new item to the table that doesn’t already exist. How would I do this? I googled the hell out of this, but didn’t find this exact scenario. Sorry but I cannot share the code for the page I am trying to text.

I am trying this, but it won’t click anything:

@{locators}=     Get Webelements    xpath=//div/table
${result}=       Create List

:FOR   ${locator}   in    @{locators}
\       ${name}=    Get Text    ${locator}
\       Click Element    xpath=//div/li[not(contains(., '${result}'))]    ${name}

Hi Greg,

In your code ${result} is an empty list, perhaps you just removed the values? even so it’s a list so I don’t think you can put it into an xpath like that.

Can you copy the html and change the sensitive values? then we might have a better chance of helping (I have worked for organisations that are sensitive about data before I do understand)

As a generic answer here is some example html I just made up if you can modify it to be a similar structure to what you have we can use this as the example:

<div>
<table>
<tr>
<td>cell 1-1</td><td>cell 1-2</td><td>cell 1-3</td><td>cell 1-4</td><td>cell 1-5</td>
</tr>
<tr>
<td>cell 2-1</td><td>cell 2-2</td><td>cell 2-3</td><td>cell 2-4</td><td>cell 2-5</td>
</tr>
<tr>
<td>cell 3-1</td><td>cell 3-2</td><td>cell 3-3</td><td>cell 3-4</td><td>cell 3-5</td>
</tr>
<tr>
<td>cell 4-1</td><td>cell 4-2</td><td>cell 4-3</td><td>cell 4-4</td><td>cell 4-5</td>
</tr>
</table>
</div>

so if you want the values from row 3 you would do something like this:

# Get Webelements returns a list of Webelements
@{cells}=     Get Webelements    xpath=//div/table/tr[3]/td
${result}=       Create List
:FOR   ${cell}   in    @{cells}
\       ${name}=    Get Text    ${locator}
\       Append To List    ${result}    ${name}

( Append To List come from the Collections library )
(Also note this is the old for loop syntax )

The bit i’m really understanding what you are trying to do is:

\       Click Element    xpath=//div/li[not(contains(., '${result}'))]    ${name}

I think what you are trying to do is click any list item (/li) that is not in the list collected from the table? but are these list items in the table or outside the table?

here is a guess at what you want:

${count} =	Get Element Count    xpath=//div/li
:FOR    ${i}    IN RANGE    ${count}
\       ${listitem}=    Get Text    xpath=//div/li[${i}]
\       Run Keyword Unless    ${listitem} in ${result}    Click Element    xpath=//div/li[${i}]

Hope this helps,

Dave.

Thanks Dave. I combined what you said to do and made some adjustments. I wanted to first get the entire table because I didn’t think that there was a way to get an entire column or to get every row with each column. The test runs as far as opening the li dropdowns, but does not select an li and instead says ‘xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[0]’ not found.

Here is my code:
@{cells}= Get Webelements xpath=//div[(@class=‘x-grid-item-container’)]
${result}= Create List
:FOR ${cell} IN @{cells}
\ ${name}= Get Text ${cell}
\ Append To List ${result} ${name}
END

${count} = Get Element Count xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li
:FOR ${i} IN RANGE ${count}
\ ${listitem}= Get Text xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${i}]
\ Run Keyword Unless ${listitem} in ${result} Click Element xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${i}]
END

Hi Greg,

Ah yes, xpaths use a 1 base count not a 0 base (so annoying, why doesn’t everything use 0 base? /rant)

you’ll need this small variation, basically you add 1 to I and then use the incremented value:

${count}=    Get Element Count    xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li
:FOR ${i} IN RANGE ${count}
\    ${iplus}=    evaluate    ${i} + 1
\    ${listitem}=    Get Text    xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${iplus}]
\    Run Keyword Unless    ${listitem} in ${result}    Click Element  
  xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${iplus}]
END

there are other ways this can be done, but this is simple and reminds you later why you did it

Dave.

Thank you Dave. I am now able to click the next available li in the dropdown. However instead of stopping and moving to the next test step, the test errors after because it tries to click another available li, which there isn’t one because the dropdown is no longer displayed. So how do I get it to stop after it clicks that li element?

Here is my code now:
@{cells}= Get Webelements xpath=//div[(@class=‘x-grid-item-container’)]//td[3]
${result}= Create List
:FOR ${cell} IN @{cells}
\ ${name}= Get Text ${cell}
\ Append To List ${result} ${name}
END

${count}= Get Element Count xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li
:FOR ${i} IN RANGE ${count}
\ ${iplus}= evaluate ${i} + 1
\ ${listitem}= Get Text xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${iplus}]
\ Run Keyword Unless “${listitem} in ${result}” Click Element
xpath=//div[contains(@class, x-boundlist’)]not(contains(@style, ‘none’))]//li[${iplus}]
END