0

How Can I store all searched values from table to a list? I am unable to locate table result.

WebElement names = driver.findElement(By.xpath("//*[@id='idnumber']/div[3]/table"));
Thread.sleep(100000);

List<WebElement> TotalRowCount = names.findElements(By.xpath("//*[@id='idnumber']/div[3]/table/tbody[2]/tr"));

System.out.println(TotalRowCount);

Even for this basic code, it's giving an error that it's unable to locate element.

First I want to find element from table and I want to select radiobutton of that searched value. Please help us.

MarthyM
  • 1,839
  • 2
  • 21
  • 23
Mukta patil
  • 43
  • 1
  • 6

2 Answers2

0

You have to solve your problem first, I mean it looks like you are using wrong xpath for your locating elements.if you are not sure how to find out xpath of your element, please go Is there a way to get the xpath in google chrome?.

your System.out.println(rowCount); doesn't make sense to me, it just prints out and string representation for that object, you should use something like rowcount.size();

After you can correctly locate your web element you then can use for loop to get all rows from your table.

Community
  • 1
  • 1
Jegg
  • 549
  • 3
  • 11
0

There are several problems.

1) Your first line is storing a single TABLE tag in names then the third line is searching below names using names.findElements() but your second XPath contains the XPath from the first element. Unless you have nested tables, both with the same structure this is likely the issue.

2) Why do you have a sleep() between these lines, let alone such a long one? THere's no reason for it.

3) Your sysout isn't going to print anything human readable.

Try this instead:

List<WebElement> TotalRowCount = driver.findElements(By.xpath("//*[@id='idnumber']/div[3]/table/tbody[2]/tr"));
System.out.println(TotalRowCount.size());

You should spend some time reading some Java and Selenium tutorials. Grab a book or two and read them to better understand what you are trying to do.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • yes I did that mistake. even though trying your code I am not able to get row count size.. – Mukta patil Aug 20 '15 at 05:22
  • What does it return? It should return the number of elements returned by the XPath you supplied... is the XPath correct? – JeffC Aug 20 '15 at 14:40
  • I got the solution. It was the problem with time required for element to locate. And it has been solved. Now I am able to access required element from table. Thanks :) – Mukta patil Aug 24 '15 at 11:09