Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Selenium Openhouse CP-SAT - Handling Dynamic Web Tables


Published on

Selenium Open House - Handling Dynamic Web Tables

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Selenium Openhouse CP-SAT - Handling Dynamic Web Tables

  1. 1. Selenium- Open House CP-SAT 24th September 2020 7-8 PM
  2. 2. Agenda 1.Introduction 2.How to handle dynamic web tables using Selenium 3.Open house – Questions 4. Code base sharing
  3. 3. ▪ Steering Committee Member, Agile and DevOps Coach at Agile Testing Alliance and DevOps++ Alliance ▪ Licensed Trainer Agile Testing – ATA (CPSAT (Selenium Automation Testing), CPDOF (DevOps), CPCCT (Cucumber Driven Continuous Testing), CPMAT (Master Agile Testing)),Qualified Project Management Professional (QPMP), CSM, SAFE SDP, Six Sigma Black Belt, ISTQB certified foundation and advanced level Tester, Sun Certified Java Programmer, Presenter in International conferences on Project Management, Agile, DevOps, Quality and Testing ▪ Co-Author of a book on Selenium ▪ 24+ years of IT Industry experience with: ▪ Agile Testing Alliance , Larsen & Toubro Infotech Ltd, India, NSE.IT (National Stock Exchange, India) ▪ Celox Networks, USA, Netscout Systems, USA ▪ BE CSE, MBA Finance from UMASS Lowell. Aditya Garg Enterprise Agile and DevOps Coach, DevOps trainer and consultant
  4. 4. About CP-SAT
  5. 5. It is accepted globally for more than 5 years now One of the oldest and best certification program in Selenium #1 Global Certification Program in Selenium
  6. 6. Accepted by major IT organizations and MNC’s Driven by Agile Testing Alliance – a global body present across 24 countries #1 Global Certification Program in Selenium
  7. 7. Only program to have practical assessment Two Assessments 1. Theory (60 mins MCQ) 2. Practical (150 mins) #1 Global Certification Program in Selenium
  8. 8. Only program which is technology agnostic. Assessment can be taken up in any of the below tech. 1. Java 2. Python 3. C# #1 Global Certification Program in Selenium
  9. 9. Let us jump into action Web Tables
  10. 10. What is a Web Table
  11. 11. //*[@id="customers"]/tbody/tr Handling a static web table with fixed numbers of rows on display is simple In the previous example below will give us all the Rows Using for loop we can browse through the rows and get the columns in that row //*[@id="customers"]/tbody/tr[i]/td For loop has to run from ? (initial and last value?) Very important as the i is dependent on the correct loop values. If we get a list of WebElements = what will be the size in this example Demo
  12. 12. Dynamic Web Table
  13. 13. styling/jqueryUI.html
  14. 14. //*[@id="example"]/tbody/tr Gives us all the rows displayed //*[@id="example"]/tbody/tr[1] Gives us the first row //*[@id="example"]/tbody/tr[10] Gives us the last row We want to capture all the rows in this table. It has 57 rows
  15. 15. If we can click on these. Wait for the table to populate then the problem is simple. We have to then handle tables on each click
  16. 16. //*[@id="example_paginate"]/span/a Gives us a list of all the buttons at the bottom. We can click one by one and then browse through the table Please note that the first one is already clicked. We do not want to click the first one. We start from second
  17. 17. @Test public void f() { // get all the pagination elements By paginationSpan = By.xpath("//*[@id="example_paginate"]/span/a"); List <WebElement> pages = driver.findElements(paginationSpan); // process the first table // click and process from the second table onwards // index starts from 0 - we are doing 1 as we want the second // for (int i = 1; i < pages.size(); i++) { WebElement eachTablePage = pages.get(i);; // process the new table } Would this work ? FAILED: f lenium.StaleE lementReferen ceException: stale element reference: element is not attached to the page document (Session info: chrome=85.0.4 183.102)
  18. 18. //*[@id="example_paginate"]/span/a[2] //*[@id="example_paginate"]/span/a[6] Process the first table Process the next table In a for loop click on the next page. And process the table To process the table we modularize our code and keep inside a method
  19. 19. // method to process the table public void processTable() { String rowXpath = "//*[@id='example']/tbody/tr"; By locatorRow = By.xpath(rowXpath); List <WebElement> allRowsList = driver.findElements(locatorRow); int listsize = allRowsList.size(); // go through each row and get all the columns // construct a xpath for each row // //*[@id='example']/tbody/tr[i]/td // List index is from 0. // table row index is from 1 // we want from the 1 to 10 row onwards for (int i = 1 ; i <= listsize; i++) { String column = "//*[@id='example']/tbody/tr["+i+"]/td"; //System.out.println("Getting columns for the xpath = " + column); By columnXpath = By.xpath(column); List <WebElement> allColumns = driver.findElements(columnXpath); // browse through all the columns and print them on the console System.out.print("Row " + i + " = "); for (int j = 0; j<allColumns.size() ; j++ ) { WebElement columnElement = allColumns.get(j); System.out.print(columnElement.getText()+"::"); } // print new line. System.out.println(); } } ProcessTable method is same as our static web table. We process the rows and columns similarly
  20. 20. Questions ?
  21. 21. Only program to have practical assessment Two Assessments 1. Theory (60 mins MCQ) 2. Practical (150 mins) #1 Global Certification Program in Selenium
  22. 22. git clone Code Base
  23. 23. Thank you #1 Global Certification Program in Selenium