Selenium + Node
Introduction to Selenium Webdriver Introduction to Node.js Installation and Environment set up NPM – Package Manage for Node.js Directory layout of Selenium Webdriver Node.js package Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methodsAssertions in Selenium in Node.js Interacting with elements in Selenium in Node.js Basic Browser window automation Sending keys in Selenium in Node.js Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in Node.js Executing JavaScript in Selenium in Node.js Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Common exceptions in Selenium Taking a screenshot in selenium Mocha – Unit testing framework Selenium gridWorking with tables in Selenium in node
In this topic, You will learn how to perform below operations on table using Selenium.- Find total number of rows and columns in a table
- Read a value from the table cell
- Click on elements inside table cells
- Finding total number of rows and columns in a table
- //table//tr – This XPATH can be used to get all tr elements inside the table. Note that if there are nested tables, it will get all nested tr elements as well. To get only immediate child tr elements, you will have to use children property which returns collection of child tr elements. Alternatively you can use “//table/tr” XPATH to find only immediate child tr elements. Note that we have used single / which means find only immediate children.
- //table//th -This XPATH can be used to find total number of columns in a table. Note that all column headings should be marked with th tag. Also note that if one th tag spans multiple columns, it will be counted only once.
- //table//tr[1]//td – This XPATH finds all td elements (table cells) in the first row of the table. Note that all nested td elements will be found using this XPATH expression.
var tableCells = driver.findElements(By.tagName(“//table//td”));
tableCells .then(function (elements) {
console.log(“Total number of cells -> ” + elements.length+ “
”);
//Print data from each cell
for (var i=0; i < elements.length; i++){
elements[i].getText().then(function(txt){
console.log(txt + “
”);
});
}
});
Web development and Automation testing
solutions delivered!!