Item 1
Item 2
Items count: {this.state.itemCount}
```
#### Selecting elements by the component name
To get a root DOM element for a component, pass the component name to the `ReactSelector` constructor.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const todoInput = ReactSelector('TodoInput');
```
#### Selecting nested components
To obtain a nested component or DOM element, you can use a combined selector or add DOM element's tag name.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const TodoList = ReactSelector('TodoApp TodoList');
const itemsCountStatus = ReactSelector('TodoApp div');
const itemsCount = ReactSelector('TodoApp div span');
```
Warning: if you specify a DOM element's tag name, React selectors search for the element among the component's children without looking into nested components. For instance, for the JSX above the `ReactSelector('TodoApp div')` selector will be equal to `Selector('.todo-app > div')`.
#### Selecting components by the component key
To obtain a component by its key, use the `withKey` method.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const item = ReactSelector('TodoItem').withKey('HighPriority');
```
#### Selecting components by display name
You can select elements by the component's [displayName](https://reactjs.org/docs/react-component.html#displayname).
For instance, consider the `TodoList` component whose `displayName` class property is specified as follows:
```js
class TodoList extends React.Component {
// ...
}
TodoList.displayName = 'TodoList';
```
In this instance, you can use `todo-list-display-name` to identify `TodoList`.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const list = ReactSelector('todo-list-display-name');
```
#### Selecting components by property values
React selectors allow you to select elements that have a specific property value. To do this, use the `withProps` method. You can pass the property and its value as two parameters or an object.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const item1 = ReactSelector('TodoApp').withProps('priority', 'High');
const item2 = ReactSelector('TodoApp').withProps({ priority: 'Low' });
```
You can also search for elements by multiple properties.
```js
import { ReactSelector } from 'testcafe-react-selectors';
const element = ReactSelector('componentName').withProps({
propName: 'value',
anotherPropName: 'differentValue'
});
```
##### Properties whose values are objects
React selectors allow you to filter components by properties whose values are objects.
When the `withProps` function filters properties, it determines whether the objects (property values) are strictly or partially equal.
The following example illustrates strict and partial equality.
```js
object1 = {
field1: 1
}
object2 = {
field1: 1
}
object3 = {
field1: 1
field2: 2
}
object4 = {
field1: 3
field2: 2
}
```
* `object1` strictly equals `object2`
* `object2` partially equals `object3`
* `object2` does not equal `object4`
* `object3` does not equal `object4`
Prior to version 3.0.0, `withProps` checked if objects are strictly equal when comparing them. Since 3.0.0, `withProps` checks for partial equality. To test objects for strict equality, specify the `exactObjectMatch` option.
The following example returns the `componentName` component because the `objProp` property values are strictly equal and `exactObjectMatch` is set to true.
```js
// props = {
// simpleProp: 'value',
// objProp: {
// field1: 'value',
// field2: 'value'
// }
// }
const element = ReactSelector('componentName').withProps({
simpleProp: 'value',
objProp: {
field1: 'value',
field2: 'value'
}
}, { exactObjectMatch: true })
```
Note that the partial equality check works for objects of any depth.
```js
// props = {
// simpleProp: 'value',
// objProp: {
// field1: 'value',
// field2: 'value',
// nested1: {
// someField: 'someValue',
// nested2: {
// someField: 'someValue',
// nested3: {
// field: 'value',
// someField: 'someValue'
// }
// }
// }
// }
// }
const element = ReactSelector('componentName').withProps({
simpleProp: 'value',
objProp: {
field1: 'value',
nested1: {
nested2: {
nested3: {
field: 'value'
}
}
}
}
}, { exactObjectMatch: false })
```
#### Searching for nested components
You can search for a desired subcomponent or DOM element among the component's children using the `.findReact(element)` method. The method takes the subcomponent name or tag name as a parameter.
Suppose you have the following JSX.
```xml