0

I have difficulty in an if test where I wan't to test if the text of my element is equel to a string. I'm doing it like this :

WebElement vote1 = chromeDriver.FindElementByXPath("//*[@data-website-id=\"4\"]");
Console.WriteLine(vote1.GetAttribute("text")); 
if (vote1.GetAttribute("text").Equals("Vote N°1 [1H30]"))
{
    Console.WriteLine("Votable");
    chromeDriver.FindElementByXPath("//*[@data-website-id=\"4\"]").Click();
}

But while doing this my console is showing me this : Console result

Because the first writeline give me the exact same text that in the equals, I don't understand why the if is false. What am I doing wrong ?

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
  • Have you tried with trimmed text that you got using `getAttribute`, to rule out if there are any white spaces? – supputuri Apr 23 '20 at 03:18
  • Not sure if StringComparer.OrdinalIgnoreCase function will help you because your string is having special character. You can refer https://stackoverflow.com/questions/37280155/c-sharp-string-comparison-fails-for-string-having-special-character-in-it for more details – Amruta Apr 23 '20 at 04:15
  • I finally was able to make it work by checking if my vote1 text had the string Vote using the Contains() function. I think it's not the best way but it worked fine. I will go check your answer to make a proper code thanks. – Powablocks Apr 23 '20 at 21:35

0 Answers0