Selenium get element contains/not contains multiple classes with cssSelector

  • 1 Replies
  • 6106 Views
I'm trying to write a UI test with selenium on a FuelUX Repeater control,
i need to determine which one of the repeater-views is active and which is not.
http://getfuelux.com/javascript.html#repeater

Firstly i thought i would find the label element which has both classes 'btn' and 'active', and then i would search for another label element which has 'btn' class but does not have 'active'.

I tried doing so via Css selector :
Code
WebElement activeButton = repeaterViews.findElement(By.cssSelector("label.btn.active"));

Is it possible to find an element which does not have 'active' class ?

Code
<div class="btn-group repeater-views" data-toggle="buttons">
     <label class="btn btn-default">
          <input name="repeaterViews" type="radio" value="list" class=""><span class="glyphicon glyphicon-list"></span>
     </label>
     <label class="btn btn-default active">
          <input name="repeaterViews" type="radio" value="thumbnail" class=""><span class="glyphicon glyphicon-th"></span>
     </label>
</div>


*

Haim

  • *
  • 10
Yes,
you would have a much easier time using Xpath.
      
Code
WebElement inactiveButton = repeaterViews.findElement(By.xpath("//label[contains(@class, 'btn') and not(contains(@class, 'active'))]"));

This will select the other button element which does not have 'active' class on.

 

Sitemap 1 2 3 4 5 6 7 8