javaseleniumselenium-webdriverclassnameng-hide

How to avoid the hidden classes using selenium webdriver


I am trying to refer to a class using classname with selenium but the same class got a hidden tag with exactly same name and all other values except ng-show=false

AS below:

ul class="nav nav-pills nav-stacked ng-hide" ng-show="false" <br>
ul class="nav nav-pills nav-stacked"

How can I refer to the second tag?
I didn't try @tabIndex as sometimes, the hidden tags are more than one.


Solution

  • You can find by the missing class ng-hide. Find element witch has the classes nav nav-pills nav-stacked but not ng-hide

    driver.findElement(By.cssSelector(".nav.nav-pills.nav-stacked:not(.ng-hide) > div"));
    

    Or by not having ng-show="false"

    driver.findElement(By.cssSelector(".nav.nav-pills.nav-stacked:not([ng-show='false']) > div"));