Get values from the table using Selenium WebDriver -
Print particular row of column value
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class getValuesFromTable {
@Test
public void webdriverReadTable() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://content.icicidirect.com/newsiteContent/Market/MarketStats.asp?stats=DailySharePrices");
Thread.sleep(5000);
WebElement elementTable = driver.findElement(By.id("gridSource"));
List<WebElement> rows = elementTable.findElements(By.tagName("tr"));
int rowNumber = 0;
for(WebElement row : rows) {
rowNumber++;
List<WebElement> cols = row.findElements(By.tagName("td"));
int colNumber = 0;
for(WebElement col : cols) {
colNumber++;
if(rowNumber==4 && colNumber == 6) {
System.out.println("The 3rd row of 5th column element is: "+ col.getText());
}
// System.out.println("Each col is "+col.getText());
}
}
System.out.println(rows.get(2).getText());
driver.close();
}
}
Output:
The 3rd row of 5th column element is: 5791
Aadi Indus 4.22 4.22 4.22 4.22 2 1 4.00
Print particular row of column value
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class getValuesFromTable {
@Test
public void webdriverReadTable() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://content.icicidirect.com/newsiteContent/Market/MarketStats.asp?stats=DailySharePrices");
Thread.sleep(5000);
WebElement elementTable = driver.findElement(By.id("gridSource"));
List<WebElement> rows = elementTable.findElements(By.tagName("tr"));
int rowNumber = 0;
for(WebElement row : rows) {
rowNumber++;
List<WebElement> cols = row.findElements(By.tagName("td"));
int colNumber = 0;
for(WebElement col : cols) {
colNumber++;
if(rowNumber==4 && colNumber == 6) {
System.out.println("The 3rd row of 5th column element is: "+ col.getText());
}
// System.out.println("Each col is "+col.getText());
}
}
System.out.println(rows.get(2).getText());
driver.close();
}
}
Output:
The 3rd row of 5th column element is: 5791
Aadi Indus 4.22 4.22 4.22 4.22 2 1 4.00
I wish to indicate because of you only to bail me out of this specific trouble.As a consequence of checking through the net and meeting systems that were not beneficial, I thought my life was finished.
ReplyDeleteselenium training in bangalore|
hi
ReplyDeleteselenium training in bangalore|