Created
August 15, 2022 01:54
-
-
Save bharathmuddada/a03bc09d521d8c6709d6e5911449fcb9 to your computer and use it in GitHub Desktop.
C# Selenium program to extract data from web table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SeleniumWebTableDataExtraction { | |
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"); | |
//Get the email address of Frank | |
var rows = driver.FindElements(By.XPath("//table[@id='table1']//tbody/tr")); | |
var columns = driver.FindElements(By.XPath("//table[@id='table1']//tbody/tr[1]/td")); | |
for (int i = 1; i <= rows.Count; i++) { | |
for (int j = 1; j <= columns.Count; j++) { | |
var tableelement = driver.FindElement(By.XPath($"//table[@id='table1']//tbody/tr[{i}]/td[{j}]")); | |
Console.WriteLine(tableelement.Text); | |
} | |
} | |
for (int i = 1; i <= rows.Count; i++) | |
{ | |
for (int j = 1; j <= columns.Count; j++) | |
{ | |
var FirstName = driver.FindElement(By.XPath($"//table[@id='table1']//tbody/tr[{i}]/td[{j}]")); | |
if (FirstName.Text == "Frank") | |
{ | |
var email = driver.FindElement(By.XPath($"//table[@id='table1']//tbody/tr[{i}]/td[{3}]")); | |
Console.WriteLine($"email of {FirstName.Text} is {email.Text}"); | |
} | |
} | |
} | |
driver.Quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment