Handling Web Table or HTML Table using Selenium
https://youtu.be/kTQmAPK1wj4---------------------------------------
A table consists of rows and columns. The table created for a web page is called a web table.
Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either be static or dynamic in nature.
Handling Elements in Selenium
Web table in Selenium is a WebElement just like any other popular WebElements like text boxes, radio buttons, checkboxes, drop-down menus, etc. Web table and its contents can be accessed by using the WebElement functions along with locators to identify the element (row/column) on which the operation needs to be performed.
Handling Web Table or HTML Table
> Check Displayed status
> Return a Cell value
> Return rows count
> Return cells count
> Return columns count
Selenium WebDriver Test Steps:
System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("file:///C:/Users/Hello/Desktop/Customer.html");
boolean status = driver.findElement(By.xpath("/html/body/table")).isDisplayed();
System.out.println(status);//true
WebElement customerTable = driver.findElement(By.xpath("/html/body/table"));
List rows = customerTable.findElements(By.tagName("tr"));
int row_Count=rows.size();
System.out.println(row_Count);//4
List cells = customerTable.findElements(By.tagName("td"));
int cell_Count = cells.size();
System.out.println(cell_Count);//12
int column_Count = cell_Count/row_Count;
System.out.println(column_Count);//3
String cellValue = driver.findElement(By.xpath("/html/body/table/tbody/tr[2]/td[2]")).getText();
System.out.println(cellValue);//Smith
driver.close();