0

In selenium-webdriver (Java),

We can get the GWT element
for eg. WebElement obj = driver.findElement(By.id("gwt-debug-celltable"));

By obj we can get that webelement of the celltable but we won't get the actual celltable. So if want to check the number of records in the celltable using Selenium-Webdriver. What i need to do?

Is it possible? If yes please answer asap.

Gnik
  • 7,120
  • 20
  • 79
  • 129
  • 2
    If you mean you want to query the java object that GWT has compiled into the HTML that your webdriver has just gotten, the answer is probably no. That's the sort of thing unit tests are for. – Roddy of the Frozen Peas Aug 29 '12 at 15:04

2 Answers2

1

Yes. You can do it using xpath, somehow:

List<WebElement> elements =
     driver.findElements(By.xpath("//table[@id='gwt-debug-celltable']/tbody/tr"));

In elements will be the list of rows. I have not tested this code. But it likes one that we are using in our project.

ilalex
  • 3,018
  • 2
  • 24
  • 37
  • 2
    why not just find the elements by id? xpath is not the most preferred way to find things because of speed – Greg Aug 29 '12 at 18:16
  • Because tr-tags have no id in gwt. Of course, you can find the table element by id and do recursive find. But I think xpath more elegant way for do it. – ilalex Aug 29 '12 at 18:19
  • Or you could just add ids to your tr tags, or classes, which would be better web design anyway. – Roddy of the Frozen Peas Aug 29 '12 at 20:07
0

For the webtable i have refered the below link http://money.rediff.com/gainers/bsc/daily/groupa from the below code you can get all the values from the webtable

    public class MaxFromTable {
public static void main(String[] args) throws ParseException {
WebDriver wd;
System.setProperty("webdriver.chrome.driver","G://chromedriver.exe");
wd= new ChromeDriver();
wd.get("http://money.rediff.com/gainers/bsc/daily/groupa?"); 
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++)
        {    
            max= wd.findElement(By.xpath("html/body/div[1]/div[5]/table/tbody/tr[" + (i+1)+ "]/td[4]")).getText();
            NumberFormat f =NumberFormat.getNumberInstance(); 
            Number num = f.parse(max);
            max = num.toString();
            m = Double.parseDouble(max);
            if(m>r)
             {    
                r=m;
             }
        }
        System.out.println("Maximum current price is : "+ r);        
    }
    }