How to check that an attribute not exists in an element with PHPUnit? I'm trying to test that an element don't exists in a page. I know that exists the elementAttributeExists() method that checks that an attribute exists in an element. But I can't find any method like elementAttributeNotExists() to check that an attribute don't exists in an element.

So, with the following code I can check that the 'autocomplete' attribute is present in the #edit-pass element:

  public function testLoginForm() {
    // Going to the log in.
    $this-&gt;drupalGet('/user/login');

    // Checking that the autocomplete is not set.
    $this-&gt;assertSession()-&gt;elementAttributeExists('css', '#edit-pass', 'autocomplete');
  }


But how I can check that the autocomplete attribute is not present?
You can check if there is a matching element for #edit-pass which has the attribute. Because #edit-pass targets only one element this has the same result when you know that this element exists:

$this-&gt;assertSession()-&gt;elementNotExists('css', '#edit-pass[autocomplete]');