Title

The html section element has an implicit region acce" />

Title

The html section element has an implicit region acce" />

Title

The html section element has an implicit region acce"/>

Is it possible to find an element with accessible role and name?

131 Views Asked by At

I have an html structure like:

<section aria-labelledby="123">
  <h2 id="123">Title</h2>
</section>

The html section element has an implicit region accessibility role

Is there something like byRole selenide selector that would find the element by role and name?

e.g.:

byRole('region', 'Title')

Or can it be grabbed using xpath?

1

There are 1 best solutions below

2
Yaroslavm On

Selenide doesn't have built-in function for getting element by role and title, however, it can be easily done with xPath

For example, this locator would point for your section element with role where child exists with text that contains Title.

$x("//*[@role='region' and .//*[contains(.,'Title')]]")

or you can do it by using filter from Stream API

$$("[role=region]").stream().filter(el -> el.innerText().contains("Title"))
.findFirst().get();