Searching...
Sunday 30 December 2012

Handling Tables with same ID and Name

Handling Tables with same ID and Name

If in a page there are more then one table with same name and id, then we can identify each table using position is selenium

For example
  1. Go to "http://www.icicidirect.com". Click on the Markets Link
  2. Here we will find two tables Top Gainer and Top Losers with same id.
  3. We can identify each table uniquely using position

Below is the code
public static DefaultSelenium ds = null;
public static SeleniumServer server = null;
public static void selecttable()
{
String str;
start("http://www.icicidirect.com"); // function to launch url
Thread.sleep(3000);
ds.click("link=Markets");
Thread.sleep(5000);
str=ds.getTable("xpath=(//*[@class='tabData bdr_btm brd'])[position()=2].3.1");
System.out.println(str);
}

public static void start(String url) throws Exception
{
rc=new RemoteControlConfiguration();
rc.setPort(1111);
server = new SeleniumServer(rc);
server.start();
ds=new DefaultSelenium("localhost",1111,"*firefox",url);
ds.start();
ds.windowMaximize();
ds.open("/");
}

In the above code if we provide [position()=1] then 1st table will be selected and for [position()=2] 2nd table will be selected


0 comments:

Post a Comment

 
Back to top!