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.

    // Checking that the autocomplete is not set.
    $this->assertSession()->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->assertSession()->elementNotExists('css', '#edit-pass[autocomplete]');
  • I updated the code because with the space the code not works. – Adrian Cid Almaguer Mar 8 '18 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.