Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Dynamic Table:-

The table is used to contain the records based on rows and columns, rows will be presented by <tr> and columns will be presented by <td>.

Structure of Table:-

<table>
<thead>
<tr><th>SNO</th><th>Name</th></tr>
</thead>
<tbody>
<tr><td>1001<td><td>XYZ</td></tr>
<tr><td>1002<td><td>ABC</td></tr>
<tr><td>1003<td><td>MNO</td></tr>
<tr><td>1004<td><td>KLMN</td></tr>
<tr><td>1005<td><td>TUV</td></tr>
</tbody>


</table>


What is Dynamic Table:-


If a number of rows and columns is not fixed then it is called a dynamic table, we can also retrieve a record from Web Driver Code to dynamic Table.

Dynamic table data will be filled by the database means its rows can be changed dynamically.



Q) CREATE AUTOMATION SCRIPT to COUNT NUMBER OF ROWS and COLUMN using selenium Web Driver?


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DynamicTableExample {

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://demo.guru99.com/test/web-table-element.php");
    List col = driver.findElements(By.xpath("//*[@id=\"leftcontainer\"]/table/thead/tr/th"));
List row = driver.findElements(By.xpath("//*[@id=\"leftcontainer\"]/table/tbody/tr/td[1]"));
System.out.print("number of column is "+col.size());
System.out.print("number of rows is "+row.size());
}

}


Create Automation Script to find max price in Dynamic Table?

Answer:-

package scs;
import java.text.ParseException;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class DynamicTableExampleNew {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c://chromedriver.exe");
WebDriver wd= new ChromeDriver();
wd.get("http://demo.guru99.com/test/web-table-element.php");
// String max;
double m=0,r=0;

      //No. of Columns
List  col = wd.findElements(By.xpath(".//*[@id='leftcontainer']/table/thead/tr/th"));
System.out.println("Total No of columns are : " +col.size());
       //No.of rows
List  rows = wd.findElements(By.xpath (".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
System.out.println("Total No of rows are : " + rows.size());
for (int i =1;i<rows.size();i++)
       {    
          String max= wd.findElement(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr["+i+"]/td[4]")).getText();
          // System.out.println(max);
           m = Double.parseDouble(max);
          if(m>r)
            {    
               r=m;
           }
       }
       System.out.println("Maximum current price is : "+ r);

}


}




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post