gowtham gowtham - 1 year ago 191
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download