Balazs
Balazs

Reputation: 195

Finding a Dialog from a context using TestBench

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.

Upvotes: 1

Views: 190

Answers (1)

Fluffy Panda
Fluffy Panda

Reputation: 69

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.

Upvotes: 0

Related Questions