How to get all rows from a dynamic table using Web Driver.

166 views
Skip to first unread message

Yogesh Tyagi

unread,
Jan 13, 2014, 12:23:15 AM1/13/14
to seleniu...@googlegroups.com
How to get all rows from a dynamic table using Web Driver.

Please help me out.


Regards,
Yogesh

Ashok kumar

unread,
Jan 13, 2014, 1:34:04 AM1/13/14
to seleniu...@googlegroups.com
Yogesh,

You can work with table data using their index, this helps in accessing cells without using any Xpath or any other cell property. This can be done by the WebTable API which is part of ATU Selenium utilities API.

Ex:

String firstCellOfBody= table.getTBody().getRow(0).getCell(0).getText(); 
String secondCellOfBody= table.getTBody().getRow(0).getCell(1).getText();

Download the API from below url, you can find full example under WebTable Section.

http://automationtestingutilities.blogspot.in/


Regards
Ashok

mrigank ved

unread,
Jan 13, 2014, 1:37:07 AM1/13/14
to seleniu...@googlegroups.com
Hi Yogesh,

Check this it will help you.

First find what is the table name.

Then give the xpath of the table till the "tr" element and then use "findElemnts" and store all the objects in a list of type "WebElement"





package com.example.sel;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class TableColm {

FirefoxDriver driver=new FirefoxDriver();
public void tableColCount(){
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//table[@class='wikitable']")));
List<WebElement> totalrow=driver.findElements(By.xpath("//table[@class='wikitable']/tbody/tr"));
System.out.println(totalrow.size());
driver.quit();
}
public static void main(String[] args) {
TableColm colObj=new TableColm();
colObj.tableColCount();

Manish Bansal

unread,
Oct 1, 2015, 1:55:39 PM10/1/15
to Selenium Users

PeterJeffreyGale

unread,
Oct 1, 2015, 1:57:07 PM10/1/15
to Selenium Users
Manish

Please don't spam the forum by replying to every possible ancient thread that you can find to promote your website.

Peter

Krishnan mahadevan

unread,
Oct 2, 2015, 12:08:39 AM10/2/15
to seleniu...@googlegroups.com
Am with Peter on that!

Manish
Not sure what's the whole point in reviving threads which are like a year old just to advertise a blog/website.
It's good that you are willing to share knowledge with folks on this forum. But not at the cost of resorting to spamming! Please be considerate of the other folks in this forum.



-Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else"

From: PeterJeffreyGale
Sent: ‎01-‎10-‎2015 23:27
To: Selenium Users
Subject: [selenium-users] Re: How to get all rows from a dynamic table usingWeb Driver.

Manish

Please don't spam the forum by replying to every possible ancient thread that you can find to promote your website.

Peter

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f5ebda4b-c483-4bf7-b757-359a9427dad7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manish Bansal

unread,
Oct 2, 2015, 12:34:43 AM10/2/15
to seleniu...@googlegroups.com

Hi Peter,
My intention is to help people and not to spam,  I found something interesting therefore i thought of helping others who is looking for the similar solution, I might didn't realised if those are very old post,  that could be one thing I should be keeping in mind, nevertheless. Thanks Peter will keep this in mind.

Thanks,
Manish Bansal

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/1m0x0dir_rY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages