1

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->drupalGet('/user/login');

    // 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?

0

1 Answer 1

2

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]');
1
  • I updated the code because with the space the code not works. Commented Mar 8, 2018 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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