0

I am using Rspec and Watir-webdriver and am looking to get a count of all the elements that have been clicked.

What I'm doing:

I perform a search and get back a list of results; I then run a loop to select only 5 of them. The class name for these elements goes from asset-card selectable to now saying asset-card selectable selected.

I try to get a proper count by doing this:

count = @browser.elements(:class, 'selected').size

But this is still giving me all results and not specifically the ones that now have selected as part of the class name.

Any thoughts on how I can accomplish this?
This is what the html looks like:

<div class="search results">
    <div class="asset-card selectable selected"></div>
    <div class="asset-card selectable selected"></div>
    <div class="asset-card selectable"></div>
    <div class="asset-card selectable"></div>
    <div class="asset-card selectable"></div>
</div>

In this html example, the first two elements have been selected

kmancusi
  • 591
  • 3
  • 20
  • 2
    Are you saying that `@browser.elements(:class, 'selected')` returns elements with a class of `asset-card selectable`? If you can provide the HTML in question, that would help in reproducing your issue. – orde May 28 '16 at 00:06
  • @orde, I have updated my original post to show what the HTML is doing – kmancusi May 31 '16 at 13:12
  • 2
    @kmancusi, are you saying that `@browser.elements(:class, 'selected').size` does not return "2" for the sample HTML? – Justin Ko Jun 01 '16 at 12:58
  • @JustinKo: yes, this is initially the issue I was running into--coincidentally I resolved this just now -_- – kmancusi Jun 02 '16 at 14:14

1 Answers1

0

I feel rather dumb; I found a solution that fixes the issue of why I wasn't getting a proper count returned: it's because I wasn't waiting long enough

After I placed a sleep 1 duration, it returned a count accurate to what I was clicking on. My thought on this isn't exactly technical, but it was acting as if the click action and class name change was performing actions before a proper count could be determined.
I will be looking to place a more elegant wait solution as I'd like to avoid having to use sleep commands if possible

kmancusi
  • 591
  • 3
  • 20