Watir webdriver; counting elements with changing class names

早过忘川 提交于 2020-01-07 02:11:11

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/37492341/watir-webdriver-counting-elements-with-changing-class-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!