How To Handle Dynamic Web Table In Selenium WebDriver

If spider web tabular array has same publish of rows together with same publish of cells In each rows every fourth dimension y'all charge page together with then It Is real slow to induce that table's information In selenium WebDriver software testing tool equally described In How To Extract Table Data/Read Table Data Using Selenium WebDriver post. Now supposing your table's rows together with columns are increasing/decreasing every fourth dimension y'all loading page of software spider web application or only about rows has to a greater extent than cells together with only about rows has less cells together with then y'all ask to position only about extra code In your webdriver software test instance which tin lav remember prison theater cellular telephone information based on publish of cells In specific row. Consider the dynamic webtable shown In bellow given Image.


In this table, Row publish 1, ii together with four has iii cells, Row publish iii has ii Cells together with Row five has 1 cell. In this case, You ask to create only about extra code to induce these dynamic cells of unlike rows. To create It, You ask to detect out the publish of cells of that specific row earlier retrieving information from It.

You tin lav thought to a greater extent than webdriver software testing tutorials alongside testng together with java WEBDRIVER TUTORIAL @PART 1 and WEBDRIVER TUTORIAL @PART 2.

Bellow given instance volition showtime locate the row together with and then It volition calculate the cells from that row together with and then based on publish of cells, It volition remember prison theater cellular telephone information Information.

Run bellow given instance In your eclipse alongside testng which Is designed for inward a higher house given dynamic spider web table.
package Testng_Pack;  import java.util.List; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace cast dynamic_table {  WebDriver driver = novel FirefoxDriver();   @BeforeTest  populace void setup() throws Exception {   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);   driver.get(" ");  }   @AfterTest  populace void tearDown() throws Exception {   driver.quit();  }   @Test  populace void Handle_Dynamic_Webtable() {     //To locate table.   WebElement mytable = driver.findElement(By.xpath(".//*[@id='post-body-8228718889842861683']/div[1]/table/tbody"));   //To locate rows of table.   List<WebElement> rows_table = mytable.findElements(By.tagName("tr"));   //To calculate no of rows In table.   int rows_count = rows_table.size();      //Loop volition execute till the concluding row of table.   for (int row=0; row<rows_count; row++){    //To locate columns(cells) of that specific row.    List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));    //To calculate no of columns(cells) In that specific row.    int columns_count = Columns_row.size();    System.out.println("Number of cells In Row "+row+" are "+columns_count);        //Loop volition execute till the concluding prison theater cellular telephone of that specific row.    for (int column=0; column<columns_count; column++){     //To remember text from that specific cell.     String celtext = Columns_row.get(column).getText();     System.out.println("Cell Value Of row publish "+row+" together with column publish "+column+" Is "+celtext);    }    System.out.println("--------------------------------------------------");   }    } }

Above instance volition industrial plant for dynamic changing spider web tabular array equally good where publish of rows changing every fourth dimension y'all charge the page or search for something.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post