0

I am doing automatic test and i want to check the occurrence of an alert with the inscription "Good morning" (when i do assert). I am writing test in C# with selenium-webdriver. How should I find a reference to that object?

I am using: driver.FindElement(By. ......

Element:

<div class="alert alert-dismissable alert-info">
<button aria-hidden="true" class="close" data-dismiss="alert">×</button>
Good morning
</div>
Anne
  • 3
  • 2

1 Answers1

1

You can't query the text directly using css selectors. See this answer. What you can do is get all the elements with that class, and then iterate over them looking for the text.

var alerts = driver.FindElements(By.CssSelector("div.alert.alert-dismissable.alert-info"));
Assert.IsTrue(alerts.Any(element => element.Text.Contains("Good morning")));
Community
  • 1
  • 1
James Brierley
  • 4,630
  • 1
  • 20
  • 39