0

I use Nightwatch.js to test a website. Now I have this html code:

<div class="form-group">
    <div class="col-sm-6">
        <input id="inputTireManufacturer">
        </input>
    </div>
</div>

I need to select the input node. But there are other nodes with id="inputTireManufacturer". This means I need a selector that can select an element with class="form-group", that contains an element with class="col-sm-6" that contains an element with id="inputTireManufacturer". Something like this: .form-group:.col-sm-6:#inputTireManufacturer But this does not work. How can I do it?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Garrarufa
  • 1,145
  • 1
  • 12
  • 29

1 Answers1

2

This has syntax errors in it:

.form-group:.col-sm-6:#inputTireManufacturer

Fixing them (removing the colons):

.form-group.col-sm-6#inputTireManufacturer

This means

Selects any element with a class attribute that contains the word form-group, a class attribute that contains the word col-sm-6, and an id attribute that equals inputTireManufacturer.

You need descendant combinators:

.form-group .col-sm-6 #inputTireManufacturer

Selects any element with an id attribute that equals inputTireManufacturer that is a descendant of any element with a class attribute that contains the word col-sm-6 that is a descendant of any element with a class attribute that contains the word form-group.


However:

The id attribute specifies its element's unique identifier (ID). [DOM]

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

If you want to mark an element as part of a group of similar elements, then use a class, that is what class is for.

<div class="form-group">
    <div class="col-sm-6">
        <input class="inputTireManufacturer">
        </input>
    </div>
</div>

.form-group .col-sm-6 #inputTireManufacturer

Selects any element with a class attribute that contains the word inputTireManufacturer that is a descendant of any element with a class attribute that contains the word col-sm-6 that is a descendant of any element with a class attribute that contains the word form-group.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335