Selenium C#: string contains
I have something like:
string result = Selenium.GetText("/html/body/form/div[2]");
if (result.Contains("test")
{
bool found = true;
}
else
{
found = false;
}
My problem is using result.Contains()
returns false if there are tests, testing, etc. Also returns false for uppercase TEST, Test, etc
Is there another method that would match each character? Something like: result.M开发者_运维问答atch("test");
Thanks for helping me out.
string.StartsWith
is a good start, and then Regex
if you need more power
Pardon my awful code, though it works:
var aStartsWithB = stringA.ToUpper().StartsWith(stringB.ToUpper());
var aContainsB = stringA.ToUpper().Contains(stringB.ToUpper());
contains it should work fine:
public static void Main()
{
string result = @"/html/body/form/tests123456";
var containsTest= result.Contains("test"); // <--True
}
Just bear in mind that Contains is case sensitive
You could use a version of string.Contains case insensitive as showed on the post below.
精彩评论