for print total web table data:
package imp;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetAllTableData {
static WebDriver d;
public static void main(String[] args) {
d=new FirefoxDriver();
d.get("http://toolsqa.com/automation-practice-table/");
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List<WebElement> ele=d.findElements(By.xpath("//table[@summary='Sample Table']/tbody/tr"));
for(WebElement e:ele)
{
System.out.println(e.getText());
}
}
}
package imp;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetAllTableData {
static WebDriver d;
public static void main(String[] args) {
d=new FirefoxDriver();
d.get("http://toolsqa.com/automation-practice-table/");
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List<WebElement> ele=d.findElements(By.xpath("//table[@summary='Sample Table']/tbody/tr"));
for(WebElement e:ele)
{
System.out.println(e.getText());
}
}
}
+++++++++++++++for print row all data based on specific cell text++++
package imp;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetSpecificTextContainsTableData_1 {
static WebDriver d;
public static void main(String[] args) {
d=new FirefoxDriver();
d.get("http://toolsqa.com/automation-practice-table/");
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String sRow="1";
String sCol="2";
WebElement cellValue=d.findElement(By.xpath("//table[@summary='Sample Table']/tbody/tr[1]/td[2]"));
System.out.println("printing specific cell vale: " + cellValue.getText());
String sRowValue="Clock Tower Hotel";
for(int i=1;i<=5;i++)
{
String sVal=d.findElement(By.xpath("//table[@summary='Sample Table']/tbody/tr["+i+"]/th")).getText();
System.out.println(sVal);
if(sVal.equalsIgnoreCase(sRowValue))
{
for(int j = 1;j<=5;j++)
{
WebElement textValue=d.findElement(By.xpath("//table[@summary='Sample Table']/tbody/tr["+i+"]/td["+j+"]"));
System.out.println("text contained roe values : " + textValue.getText());
}
break;
}
}
d.quit();
}
}
No comments:
Post a Comment