0

I have a table element 'ClassTable' which contains text as follows:

"Class Name\r\nCreated By\r\nClass Type\r\nClass Code\r\nMathematics Grade 6\r\nTeacher1\r\nSchool\r\n7BD6231E\r\nManage"

The above text contains a random 8 digit Hex code 7BD6231E which changes after each validation.

Is there any way to match the whole text using Selenium WebDriver or C# with Regex like [A-F0-9]{8} for the random hex code so that my validation passes every time without any issues as the Hex Code will change every time.

I have tried the Regex [A-F0-9]{8} with ClassTable.Text.Contains function as follows but I guess Regex is not supported in Text.Contains function.

ClassTable.Text.Contains("Class Name\r\nCreated By\r\nClass Type\r\nClass Code\r\nMathematics Grade 6\r\nTeacher1\r\nSchool\r\n[A-F0-9]{8}\r\nManage");

The suggested solutions should match the whole text including the random Hex Code. Thanks.

melleck
  • 306
  • 4
  • 15
  • Instead of `String.Contains` you need to use `Regex.IsMatch(string, Regex)` – Wiktor Stribiżew May 27 '19 at 07:57
  • but your suggestion will only match the Regex inside the string? I want the whole string to match including Regex against the text contained in the web element. How can that be accomplished? – melleck May 27 '19 at 08:05
  • Matching whole string is a known issue, add `^` at the start and `$` at the end of the pattern. – Wiktor Stribiżew May 27 '19 at 08:18
  • 1
    Thanks Wiktor, so finally the following worked for me Regex.IsMatch(ClassTable.Text, @"^Class Name\r\nCreated By\r\nClass Type\r\nClass Code\r\nMathematics Grade 6\r\nTeacher1\r\nSchool\r\n[A-F0-9]{8}\r\nManage"); – melleck May 27 '19 at 09:10

0 Answers0