There will be times when none of the queries accessible to everyone will work out for you. When this time arrives, you can resort to the semantic queries. While these queries make use of HTML5 and ARIa-compliant selectors the user experience when using these attributes varies across assistive technology and browsers.
In this lesson, we will look at one of the queries that are part of the semantic queries family and allow you to find an element by its title attribute: the byTitle query.
Instructor: [0:02] Let us move to semantic queries. Semantic queries stand in second on the query priority list. You should only resort to them if none of the queries from the queries accessible to everyone lists work. This is because the user experience when interacting with the attributes these queries reflect is not the same across browsers and assistive technology.
[0:17] In this lesson, we'll focus on the title attribute and on the ByTitle query. The title attribute is not visible by default for sighted users and is often not consistently read by screen readers. Therefore, you should be able to understand why it's not a priority to query for it. If we look at our component, here we should see a span with a title saying span title.
[0:37] Let's write a test to query for it. First, let us destructure the getByTitle query from render. Then we call it and pass the title we want to query for. In this scenario, the title is span title. Now we want to assert that this span is in our UI, so let's resort once again to the toBeInTheDocument just matcher. Finally, if we run our test, we should see that it has passed.