Friday, October 26, 2012

How to retrieve a specifec cell value from a web table using Selenium WebDriver

Here in this example i covering how to retrieve a specific cell value from Web Table using Selenium WebDriver:

The below code works well if the Cell contains plain text than any other controls etc.

int rownum,colnum;
String s_xpath;
       
WebDriver driver=new FirefoxDriver();
driver.get("https://www.irctc.co.in/");
       
rownum=2;
colnum=1;
//Here i am framing the xpath with rownum and colnum       
s_xpath="//*[@id='tabslinks']/tbody/tr["+rownum+"]/td["+colnum+"]";





//getText method retrieves the cell value.
System.out.println(driver.findElement(By.xpath(s_xpath)).getText());

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.