Question: I have a simple structure of html like

```
<div>
  <div>
    <input placeholder="pl1"></input>
  </div>
  <div>
    <input placeholder="pl2"></input>
  </div>
</div>

```

and code:

```
cy.xpath('//div/div[1]/input').should('have.attr', 'placeholder', 'pl1')

```

but if run this code I catch exception like below:

> 
> 
> ```
>  CypressError: Timed out retrying: You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a 
> 
> ```
> 
> jQuery object.
>  The chai-jQuery assertion you used was:
> 
> 
> 
> > 
> > attr
> >  The invalid subject you asserted on was:
> >  []
> >  To use chai-jQuery assertions your subject must be valid.
> >  This can sometimes happen if a previous assertion changed the subject.
> > 
> > 
> > 
> 
> 
> 

The question is: how to check attribute with value presence and how to avoid this error? CSS is not a good way to find element.

Answer: 
`cy.xpath()` returns an array of elements, so you need to get the first member of that array.

With a small modification to use [`cy.first()`](https://docs.cypress.io/api/commands/first.html) to obtain the first element returned by `cy.xpath()`, the code in the OP works:

```js
cy.xpath('//div/div[1]/input')
.first()
.should('have.attr', 'placeholder', 'pl1')

```

FYI: If you want to get the `i`th member of the array instead, you can use [`cy.its(i)`](https://docs.cypress.io/api/commands/its.html#) like so:

```js
cy.xpath('//div/div[1]/input')
.its('0') // replace 0 with the index of the element in the array to assert on
.should('have.attr', 'placeholder', 'pl1')

```
Also, that *chai-jQuery assertion* can be expressed in XPath simple as:

```
//div/div[1]/input[@placeholder='pl1']

```