Search code examples
javaseleniumserenity-bdd

Serenity: Cannot find Target showing for 3 seconds


I'm trying to find a Target that is a snack-bar with a message and a button that is only visible for 3 seconds after I click on a button:

enter image description here

If I pause the debugger I do find the element with the css selector .mat-snack-bar-container: enter image description here

But in the code when I try to get the Target with the same selector it is never found not as a Target nor if I use the driver to find the element:

actor.attemptsTo(WaitUntil.the(SnackBar.SNACK_BAR_CONTAINER,isCurrentlyVisible()).forNoMoreThan(10).seconds());

I've tried isCurrentlyVisible, isVisible, isPresent and nothing.

With findElement I also get nothing:

WebElement snackBar = webDriver.findElement((By.cssSelector(".mat-snack-bar-container")));

When I see the screenshots of the steps I do see the snack-bar...

Any ideas? Thanks!


Solution

  • I found out why the actor was not able to find the snack-bar. In the file serenity.properties I had this line: serenity.step.delay=2500 which is just the time that this element was visible. If I used the driver directly this was not affected and I could see the snack-bar both in the screenshots and in the pagesource. But using the actor I could only see it in the screenshots and sometimes. Once I lowered the step delay to 500 I was able to find the element.

    Thanks everyone for you help!