Here is my method:
public void FindByText(Element view, string textValue, bool report = true)
{
try
{
cuObject = view.FindSingle(".//text[@text='" + textValue + "']");
Mouse.MoveTo(cuObject);
if(report)
Report.Success("Validation", "Object with text value '" + textValue + "' was found within the view");
}
catch
{
if(report)
Report.Failure("Validation", "Could not find the object with text value: " + textValue + ".");
cuObject = null;
}
}
Here is my code calling the method:
var statusBar = repo.ConfigurationUtility.HomeScreen.ProjectList.StatusBar;
string statusbar = "Default Routes can't be deleted";
text.FindByText(statusBar, statusbar, true);
This works fine for string that don't contain the apostrophe. I have tried:
string statusbar = "Default Routes can't be deleted";
string statusbar = "Default Routes can\'t be deleted";
string statusbar = @"Default Routes can't be deleted";
string statusbar = "Default Routes can" + @"'" + "t be deleted";
string statusbar = "Default Routes can" + '\'' + "t be deleted";
no c# escape sequence will work but when it prints to my report as failing the string is correct with all the escape sequences.
Please help have spent too many hours on this.
Apostrophe in search string??
Re: Apostrophe in search string??
Hello larvaman,
Please try using two apostrophes instead of one:
string statusbar = "Default Routes can''t be deleted";
regards,
qwertzu
Please try using two apostrophes instead of one:
string statusbar = "Default Routes can''t be deleted";
regards,
qwertzu
Re: Apostrophe in search string??
Apostrophe do not need escaping in C#, there are taken literally - otherwise your project would not even build.
If you get a failing validation, it is most probably not an apostrophe but another character, e.g. "´" or "`".
Could you please share the exact error message you get?
Regards,
Alex
Ranorex Team
If you get a failing validation, it is most probably not an apostrophe but another character, e.g. "´" or "`".
Could you please share the exact error message you get?
Regards,
Alex
Ranorex Team
Re: Apostrophe in search string??
I had problems putting apostrophe characters into variables for use via a repository item (@accessiblename=$SomeVariable), so I stopped doing that and used regular expressions instead. Or maybe I used a > comparison for starts-with. Either way I avoided apostrophes when searching for items in my AUT.
Re: Apostrophe in search string??
Thanks qwertzu,
The double apostrophes works for all three of my strings I am searching for.
Solution Found,
Larvaman
The double apostrophes works for all three of my strings I am searching for.
Solution Found,
Larvaman