2

I am trying to find a way to select this particular web element:

<snack-bar-container class="mat-snack-bar-container ng-tns-c43-25 ng-trigger ng-trigger-state snackbar-info mat-snack-bar-center ng-star-inserted" role="alert" style="transform: translateY(0%);"><!----><simple-snack-bar class="mat-simple-snackbar ng-tns-c44-26 ng-trigger ng-trigger-contentFade ng-star-inserted" style="">Asset successfully loaded! <!----><button class="mat-simple-snackbar-action ng-tns-c44-26 ng-star-inserted" style="">Close</button></simple-snack-bar></snack-bar-container>

Currently I was selecting that by text:

.//snack-bar-container//*[contains(text(),'There are errors on the page:')]

But because there will be localisation (translation of texts) it will be unreliable in a long term, question is, is how to select element, which has a class attribute that contains some specific text in class name.

As you can see my web element class is very long, and often varies, so I need to check if it contains some specific text, I tried with:

.//[contains(@class,’snackbar-info’)]

But it does not work, any suggestions? Thank you.

Matthewek
  • 1,519
  • 2
  • 22
  • 42
  • I see no elements with text `"There are errors on the page"'`... Update your HTML sample – Andersson Dec 04 '18 at 15:27
  • Hi @Andersson it is child of the element that I pasted in the first post, but for this question I thought it is not relevant, because question is how to select element that has class name that contains some text, thank you – Matthewek Dec 04 '18 at 15:31

1 Answers1

9

Your statement is almost correct. You only are missing the SelectAll (*) at the beginning of your Statement. Just add it, and the XPath should work:

//*[contains(@class, "snackbar-info")]
Tobi
  • 414
  • 3
  • 9