0
votes

I'm very new to Ruby, Selenium, and UI automation, and have a quick question on how to get a count of visible items in a drop down menu.

Example: I have a drop down menu of 10 currency values (USD, EUR, JPN, etc.). They're coded as:

<div class="list_item">Currency Symbol</div>

The drop down menu is searchable, and if I type in "USD", then the only visible item would be that particular currency value. All other div of that class get a style="display: none;" attribute. How do I verify that that USD indeed is the only item in the menu? An example of such a situation can be seen here: https://www.oanda.com/currency/converter/

Conceptually, I was thinking of doing this:

  1. Iterate through each div tag with class=List_item, and if I find one that has a display, count it. Then verify if it equals to '1'.

I tried using find_elements but can't seem to find attribute within each element in the array (is it because they aren't webdriver objects?).

If there's another better approach, it'd be really good to know and learn more as well. Appreciate any responses.

1
Do you have any more code? - Eric Duminil
It would help if share the HTML for a complete list, which has some items visible and some that are not. - Justin Ko
Sure! The specific page I was looking at for practice is here: oanda.com/currency/converter - Jacob Simmons

1 Answers

2
votes

So, in this particular example, you could do

@driver.find_elements(:xpath, "//div[@class='currency_dropdown']/div[@id='scroll-innerBox-1']/div[not(@style='display: none;')]").size

This should return 1 when USD is typed into the search field.

Edit: I recommend getting ChroPath for your preferred browser (FF or Chrome). It helps significantly when testing xpath.