- Nov 27, 2022
- admin
- 0
//Handling Web table in Selenium
In following example, we are reading the data from above web table and getting 2nd company price..
public class clsWebtable
{
public IWebDriver dr;
[SetUp]
public void Setup()
{
Console.WriteLine("I am from setup method");
dr = new ChromeDriver(@"C:\Users\username\Desktop"); //Path of your chrome driver
}
[Test]
public void Get2ndCompanyDetails()
{
Console.WriteLine("started executing Get2ndCompanyDetails at" + DateTime.Now.ToString());
dr.Navigate().GoToUrl("https://www.moneycontrol.com/stocks/marketinfo/marketcap/bse/index.html");
IWebElement secondCompany = dr.FindElement(By.XPath("//table[@class='Topfilter_web_tbl_indices__1oyWE undefined']/tbody/tr[2]/td[1]"));
Console.WriteLine("2nd company name is:" + secondCompany.Text);
IWebElement secondCompanyPrice = dr.FindElement(By.XPath("//table[@class='Topfilter_web_tbl_indices__1oyWE undefined']/tbody/tr[2]/td[2]")); //This will get 2nd row 2nd column
Console.WriteLine("2nd company price is:" + secondCompanyPrice.Text);
Console.WriteLine("Ended executing Get2ndCompanyDetails at" + DateTime.Now.ToString());
}
}