- mkunda
- Posts : 4
Join date : 2010-03-21
Retrieving number of rows in a table
Sun Mar 21, 2010 12:59 am
Hi
I am new to Selenium. I am using Selenium with Java. I would like to retrieve number of rows of a table and need to retrieve content of each row of a specific column to validate. I can identify the table only with "id" property. But that ID property is not consistent. And I don't have any other property to identify the table.
Please help me out.
Thanks in advance
I am new to Selenium. I am using Selenium with Java. I would like to retrieve number of rows of a table and need to retrieve content of each row of a specific column to validate. I can identify the table only with "id" property. But that ID property is not consistent. And I don't have any other property to identify the table.
Please help me out.
Thanks in advance
Re: Retrieving number of rows in a table
Sun Mar 21, 2010 11:29 am
hi,
checkout this post , may be this will help you
https://seleniumforum.forumotion.net/selenium-ide-discussion-f3/how-to-store-number-of-rows-of-a-table-t69.htm?highlight=table
Best of luck.
Bye
checkout this post , may be this will help you
https://seleniumforum.forumotion.net/selenium-ide-discussion-f3/how-to-store-number-of-rows-of-a-table-t69.htm?highlight=table
Best of luck.
Bye
- mkunda
- Posts : 4
Join date : 2010-03-21
Re: Retrieving number of rows in a table
Sun Mar 21, 2010 2:19 pm
Thanks for the quick response. I have seen the post. But I dont under stand how to use this statement.
I am trying in the following way
Selenium sel = new Selenium();
s=sel.storeXpathCount("");
But I coudnt see any predefined method called storeXpathCount with Selenium. Do I need any Jar file for this.
Thanks in Advance
I am trying in the following way
Selenium sel = new Selenium();
s=sel.storeXpathCount("");
But I coudnt see any predefined method called storeXpathCount with Selenium. Do I need any Jar file for this.
Thanks in Advance
Re: Retrieving number of rows in a table
Mon Mar 22, 2010 1:19 pm
yes , you have to call selenium-server.jar into your code so that all function/API of selenium core can be accessible to you.
Checkout this post to get an idea:
https://seleniumforum.forumotion.net/selenium-rc-discussion-f4/can-t-make-rc-code-to-run-t165.htm
Checkout this post to get an idea:
https://seleniumforum.forumotion.net/selenium-rc-discussion-f4/can-t-make-rc-code-to-run-t165.htm
- mkunda
- Posts : 4
Join date : 2010-03-21
Re: Retrieving number of rows in a table
Tue Mar 23, 2010 11:22 am
Hi Adviser,
thanks for the quick reply I have added all the libraries. I am able to see sel.getXpathCount. But I am not able to see sel.storeXpathCount.
Actually I wanted to validated a text field value and as well as a table cell value.
I have added the following jar files
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
import org.openqa.selenium.*;
import org.openqa.selenium.server.SeleniumServer;
Could you tell me the exact steps or code for this.
Sorry to ask too much in details .
thanks for the quick reply I have added all the libraries. I am able to see sel.getXpathCount. But I am not able to see sel.storeXpathCount.
Actually I wanted to validated a text field value and as well as a table cell value.
I have added the following jar files
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
import org.openqa.selenium.*;
import org.openqa.selenium.server.SeleniumServer;
Could you tell me the exact steps or code for this.
Sorry to ask too much in details .
- metmanAmateur
- Posts : 58
Join date : 2010-04-02
Re: Retrieving number of rows in a table
Sat Apr 03, 2010 1:39 am
Yeah, just use:
int rowCount = sel.getXpathCount(XPathToTRElements).intValue();
getXpathCount returns a Number object, but ints are usually easier to deal with in circumstances like this. Also, if you are more interested in the aggregate contents of a column than the number of rows, you can also implicitly wildcard address all table cells in all rows by using an XPath like pathToHeadOfTable/tr/td[x] where x is the cell index across all rows. Be aware that spans may mess up using a path like that though.
Edit: scratch that, I forgot Selenium doesn't have a nice way of dumping out content of a wildcard path like that. So yeah, you'd have to loop through the rows with getXPathCount() and pull out the individual tds to validate 1 by 1.
int rowCount = sel.getXpathCount(XPathToTRElements).intValue();
getXpathCount returns a Number object, but ints are usually easier to deal with in circumstances like this. Also, if you are more interested in the aggregate contents of a column than the number of rows, you can also implicitly wildcard address all table cells in all rows by using an XPath like pathToHeadOfTable/tr/td[x] where x is the cell index across all rows. Be aware that spans may mess up using a path like that though.
Edit: scratch that, I forgot Selenium doesn't have a nice way of dumping out content of a wildcard path like that. So yeah, you'd have to loop through the rows with getXPathCount() and pull out the individual tds to validate 1 by 1.
Permissions in this forum:
You cannot reply to topics in this forum