Finding a Dialog from a context using TestBench

161 Views Asked by At

I'm looking for a way to find a DialogElement from a child context. Finding it from the "root" context is working fine, but I'm building a Page component for testing and when I try to find the DialogElement using the $(DialogElement.class) approach it tries to find it in the context of the current Element, but Dialog seems to be added to the main/root context, hence it always fails. Any suggestion how to do it?

UPDATE

I found a solution that works from anywhere in the test:

DialogElement dialogElement = new ElementQuery<>(DialogElement.class).context(getDriver()).first()

UPDATE 2

Managed to improve it:

DialogElement dialogElement = $(DialogElement.class).context(getDriver()).first()

If anyone knows a more elegant one feel free to post it.

1

There are 1 best solutions below

0
Fluffy Panda On

Try DialogElement dialogElement = $(DialogElement.class).onPage().first()

onPage() defines that the query should start the search from the root of the page, in practice from the tag.