gowtham gowtham - 1 month ago 23x
C# Question

How to convert WebElement to string?

Here is the code i'm trying with . I'm using C# basic if else statement to compare.

IWebElement findtitle = driver.FindElement(By.ClassName("heading3"));

if (title = findtitle.Text)
Console.WriteLine("Test Pass");
Console.WriteLine("Test Fail");

Guy Guy

You assigning the value to title, not comparing it. Use == to compare

if (title == findtitle.Text)

If you want to compare using ignore case use

if (findtitle.Text.IndexOf(title, StringComparison.OrdinalIgnoreCase) != -1)

This will check if findtitle text contains the text of title.