Web table in selenium web driver
Simple function for click on edit image for particular record
WebElement element=driver.findElement(By.xpath("//*[@id='service']/div/div[1]"));
List<WebElement> rowCollection=element.findElements(By.xpath("//*[@id='table-list']/tbody/tr"));
System.out.println("Numer of rows in this table: "+rowCollection.size());
//Here i_RowNum and i_ColNum, i am using to indicate Row and Column numbers.
int i_RowNum=1;
for(WebElement rowElement:rowCollection)
{
List<WebElement> colCollection=rowElement.findElements(By.xpath("td"));
int i_ColNum=1;
for(WebElement colElement:colCollection)
{
System.out.println("Row "+i_RowNum+" Column "+i_ColNum+" Data "+colElement.getText());
i_ColNum=i_ColNum+1;
if (colElement.getText().equals("ritesh"))
{
//td[2] is not dynamic,In my case edit image is on td[2] for each tr
WebElement editClick = driver.findElement(By.xpath("//*[@id='table-list']/tbody/tr["+i_RowNum+"]/td[2]/a/img"));
editClick.click();
System.out.println("testing foecom="+"Row "+i_RowNum+" Column "+i_ColNum+"");
break;
}
}
i_RowNum=i_RowNum+1;
}
}
}
Simple function for click on edit image for particular record
WebElement element=driver.findElement(By.xpath("//*[@id='service']/div/div[1]"));
List<WebElement> rowCollection=element.findElements(By.xpath("//*[@id='table-list']/tbody/tr"));
System.out.println("Numer of rows in this table: "+rowCollection.size());
//Here i_RowNum and i_ColNum, i am using to indicate Row and Column numbers.
int i_RowNum=1;
for(WebElement rowElement:rowCollection)
{
List<WebElement> colCollection=rowElement.findElements(By.xpath("td"));
int i_ColNum=1;
for(WebElement colElement:colCollection)
{
System.out.println("Row "+i_RowNum+" Column "+i_ColNum+" Data "+colElement.getText());
i_ColNum=i_ColNum+1;
if (colElement.getText().equals("ritesh"))
{
//td[2] is not dynamic,In my case edit image is on td[2] for each tr
WebElement editClick = driver.findElement(By.xpath("//*[@id='table-list']/tbody/tr["+i_RowNum+"]/td[2]/a/img"));
editClick.click();
System.out.println("testing foecom="+"Row "+i_RowNum+" Column "+i_ColNum+"");
break;
}
}
i_RowNum=i_RowNum+1;
}
}
}
Donate:
Please
Donate the some money (anything do you want) for my
blog
if you beneficial for this, I will provide more real example for the
latest
technique for whom who wants to make a carrier in IT field or solved
some
problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank
LTD :- Vaishali NCR, India-001
No comments:
Post a Comment