Home > database >  Serenity: Cannot find Target showing for 3 seconds
Serenity: Cannot find Target showing for 3 seconds

Time:10-24

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!

CodePudding user response:

I think you need to make:

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

CodePudding user response:

If you know what text will be presented then you can use textToBePresentInElementLocated method. Let's see below example,

HTML: I am assuming your HTML will be like this.

  <input class="mat-snack-bar-container"> Workflow testing "sth" saved. </input>

Wait till text presents if you know the expected text

  WebElement snackBar = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//input[@class='mat-snack-bar-container']"), "Workflow testing"));
  snackBar.click();
  • Related