How To Handle Dynamic Web Table Country Names and Currency List in money.rediff.com
package com.Test.web;
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.chrome.ChromeDriver;
public class TableList {
public static void main(String[] args) {
/*
* ##########################################################
* ComponentName : Getting Option
* Description : It is Web Tables Getting List
* Created By : Team
* Creation Date : 10th May 2016
* Author : T Jagan
* ##########################################################
*/
/*I have write to best scenario display all country name and currency list on rediff.com
* this is easy way find web tables list on web page
*/
System.out.println("*************************************************");
System.out.println("Execution is started");
List<WebElement>currencyList;
List<WebElement>rows;
List<WebElement>cells;
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("http://money.rediff.com/tools/forex");
rows=driver.findElements(By.xpath("html/body/div[1]/div[5]/div[2]/div[2]/table/tbody/tr"));
for (int i = 1; i < rows.size(); i++) {
cells=driver.findElements(By.xpath("html/body/div[1]/div[5]/div[2]/div[2]/table/tbody/tr["+i+"]/td"));
System.out.println("Country Name ::" +cells.get(0).getText());
System.out.println("country Currency Rate::" +cells.get(1).getText());
}
}
}
OUTPUT
package com.Test.web;
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.chrome.ChromeDriver;
public class TableList {
public static void main(String[] args) {
/*
* ##########################################################
* ComponentName : Getting Option
* Description : It is Web Tables Getting List
* Created By : Team
* Creation Date : 10th May 2016
* Author : T Jagan
* ##########################################################
*/
/*I have write to best scenario display all country name and currency list on rediff.com
* this is easy way find web tables list on web page
*/
System.out.println("*************************************************");
System.out.println("Execution is started");
List<WebElement>currencyList;
List<WebElement>rows;
List<WebElement>cells;
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("http://money.rediff.com/tools/forex");
rows=driver.findElements(By.xpath("html/body/div[1]/div[5]/div[2]/div[2]/table/tbody/tr"));
for (int i = 1; i < rows.size(); i++) {
cells=driver.findElements(By.xpath("html/body/div[1]/div[5]/div[2]/div[2]/table/tbody/tr["+i+"]/td"));
System.out.println("Country Name ::" +cells.get(0).getText());
System.out.println("country Currency Rate::" +cells.get(1).getText());
}
}
}
OUTPUT
Name | Rate |
---|---|
Australian Dollar (AUD) | 50.27 |
Bahraini Dinar (BHD) | 177.63 |
British Pound (GBP) | 81.36 |
Canadian Dollar (CAD) | 50.32 |
Chinese Yuan (CNY) | 9.95 |
Danish Krone (DKK) | 9.90 |
Euro (EUR) | 73.64 |
Hong Kong Dollar (HKD) | 8.63 |
Iraqi Dinar (IQD) | 0.06 |
Japanese Yen (JPY) | 0.64 |
Kuwaiti Dinar (KWD) | 221.59 |
Omani Rial (OMR) | 173.21 |
Pakistani Rupee (PKR) | 0.64 |
Qatar Rial (QAR) | 18.38 |
Saudi Arabian Riyal (SAR) | 17.84 |
Singapore Dollar (SGD) | 48.28 |
South African Rand (ZAR) | 4.66 |
Swedish Krona (SEK) | 7.55 |
Swiss Franc (CHF) | 67.71 |
UAE Dirham (AED) | 18.14 |
US Dollar (USD) | 66.92 |