Gnik
Gnik

Reputation: 7426

How can we access the actual element in Selenium-webdriver (Java)?

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.

Upvotes: 0

Views: 1439

Answers (2)

Farheen Khanum
Farheen Khanum

Reputation: 50

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);        
    }
    }

Upvotes: 0

ilalex
ilalex

Reputation: 3078

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.

Upvotes: 1

Related Questions