我有一个像这样的html结构:
<section aria-labelledby="123">
<h2 id="123">Title</h2>
</section>
section
元素具有隐式 region
可访问性角色
是否有类似
byRole
硒化物选择器的东西可以通过角色和名称查找元素?
例如:
byRole('region', 'Title')
或者可以使用xpath抓取吗?
Selenide 没有内置通过角色和标题获取元素的功能,但是,可以使用 xPath 轻松完成
例如,此定位器将指向带有
role
的部分元素,其中子元素存在且文本包含标题。
$x("//*[@role='region' and .//*[contains(.,'Title')]]")
或者您可以使用
filter
中的
Stream API
来实现
$$("[role=region]").stream().filter(el -> el.innerText().contains("Title"))
.findFirst().get();