get text inside html selenium in csharp

To get the text inside an HTML element using Selenium in C#, you can use the Text property of the IWebElement interface. Here's an example:

main.cs
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

// Create a new instance of the Chrome driver
IWebDriver driver = new ChromeDriver();

// Navigate to a web page
driver.Navigate().GoToUrl("https://example.com");

// Find an element by CSS selector
IWebElement element = driver.FindElement(By.CssSelector("#some-element"));

// Get the text inside the element
string text = element.Text;

// Do something with the text
Console.WriteLine(text);

// Quit the driver
driver.Quit();
483 chars
21 lines

In this example, we create a new instance of the Chrome driver and navigate to a web page. We then find an element using a CSS selector and get the text inside the element using the Text property. Finally, we print the text to the console and quit the driver. You can modify this code to suit your specific needs.

gistlibby LogSnag