Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created August 15, 2022 01:38
Show Gist options
  • Save bharathmuddada/e021bb2b98e38658689f0e9768b9ff64 to your computer and use it in GitHub Desktop.
Save bharathmuddada/e021bb2b98e38658689f0e9768b9ff64 to your computer and use it in GitHub Desktop.
C# Selenium Program to handle web tables
public class SeleniumWebTable {
public static void Main(string[] args)
{
//var gridurl = new Uri("http://localhost:4444");
new DriverManager().SetUpDriver(new EdgeConfig());
var driver = new EdgeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/tables");
var rows = driver.FindElements(By.XPath("//table[@id='table1']//tbody/tr"));
var columns = driver.FindElements(By.XPath("//table[@id='table1']//tbody/tr[1]/td"));
Console.WriteLine("===Rows===");
foreach (var row in rows) {
Console.WriteLine(row.Text);
}
Console.WriteLine("===Columns===");
foreach (var column in columns)
{
Console.WriteLine(column.Text);
}
var FirstRowSecondColumn_text = driver.FindElement(By.XPath("//table[@id='table1']//tbody/tr[1]/td[2]"));
Console.WriteLine("The Text from FirstRowSecondColumn : "+FirstRowSecondColumn_text.Text);
var FourthRowFifthColumn_text = driver.FindElement(By.XPath("//table[@id='table1']//tbody/tr[4]/td[5]"));
Console.WriteLine("The Text from FourthRowFifthColumn_text : " + FourthRowFifthColumn_text.Text);
driver.Quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment