Manual Actions
- Check Display status
- Return a cell value
- Return rows count
- Return cell count
- Return column count
Selenium WebDriver steps
package HandlingElementsInSelenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
public class HandlingWebTable {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
WebElement webTable = driver.findElement(By.xpath("//table[@id='product']//tbody"));
//Check displayed status
Boolean displayStatus = webTable.isDisplayed();
System.out.println("Web table is displayed :-"+displayStatus);
//Get the row count
List<WebElement> rows = webTable.findElements(By.tagName("tr"));
int rowCount = rows.size();
System.out.println("Total rows :- "+rowCount);
//Get the cell count
List<WebElement> cells = webTable.findElements(By.tagName("td"));
int cellCount = cells.size();
System.out.println("Total cell :- "+cellCount);
//Get the column count
int columnCount = cellCount/rowCount;
System.out.println("Total column is :- "+columnCount);
driver.close();
}
}
Next