I have made two functions and I have called them in main. When I execute the program it only runs the first function in the main after that program stops . if i paste the second function in main above the first one it only runs the function that is defined first but does not runs the second function.
package test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class Testing {
public static void login_and_widthdrawl() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "/home/ctp-016/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://staging.cintech.com/login");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement email = driver.findElement(By.id("email"));
email.sendKeys("zahid12#mailinator.com");
WebElement password = driver.findElement(By.id("password"));
password.sendKeys("zahid12#");
WebElement textbox = driver.findElement(By.id("login"));
textbox.click();
// checking widthdrawl functionality from here
Thread.sleep(4000);
driver.findElement(By.id("navbarDropdown")).click();
driver
.findElement(By.xpath("/html/body/app-root/div/app-header-guest/section[1]/nav/div/div/ul/li[3]/div/a[2]"))
.click();
// SELECTING BTC CRYPTO AND ENTRING VALUES FROM HERE
// WebDriverWait wait = new WebDriverWait(driver, 10);
// WebElement ele = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/app-root/div/app-withdrawal/section/div[1]/div/div/div[1]/div/div[1]/span")));
// ele.click();
Thread.sleep(2000);
WebElement submit1 = driver.findElement(By.xpath("//*[#id=\"select2\"]"));
submit1.click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
WebElement submit12 = driver.findElement(By.xpath("/html/body/span/span/span[2]/ul/li[2]"));
submit12.click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
WebElement volume =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[1]/input"));
volume.sendKeys("0.001");
WebElement wallet = driver.findElement(By.xpath(
"/html/body/app-root/div/app-withdrawal/section/div[1]/div/div/div[1]/div/div[3]/form/div[2]/div/input"));
wallet.sendKeys("1asas");
WebElement click = driver.findElement(
By.xpath("/html/body/app-root/div/app-withdrawal/section/div[1]/div/div/div[1]/div/div[3]/form/button"));
click.click();
// WebElement secret2 = driver.findElement(By.xpath("//*[#id=\"VerifyTwoFA\"]/div/div/div/app-verify-twofactor/div/div/form/div[1]/input"));
// secret2.sendKeys("0");
WebElement submit2 = driver.findElement(By.id("loginButton"));
submit2.click();
Thread.sleep(2000);
Alert alert = driver.switchTo().alert();
alert.accept();
//driver.quit();
// clear the fields
WebElement volumeclear =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[1]/input"));
volumeclear.clear();
WebElement walletclear =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[2]/input"));
walletclear.clear();
}
public static void ether() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "/home/ctp-016/Downloads/chromedriver");
WebDriver driver = new ChromeDriver();
// driver = null;
driver.get("http://staging.cintech.com/login");
// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// Thread.sleep(2000);
// WebElement selected_value_from_combo = driver.findElement(By.xpath("//*[#id=\"select2-mySelect2-result-2d1f-3\"]"));
// selected_value_from_combo .click();
// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(2000);
WebElement eth_volume =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[1]/input"));
eth_volume.sendKeys("1");
WebElement eth_wallet =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[2]/input"));
eth_wallet.sendKeys("1asas");
WebElement click_widthdrawl = driver.findElement(
By.xpath("/html/body/app-root/div/app-withdrawal/section/div[1]/div/div/div[1]/div/div[3]/form/button"));
click_widthdrawl.click();
// WebElement secret_eth = driver.findElement(By.xpath("//*[#id=\"VerifyTwoFA\"]/div/div/div/app-verify-twofactor/div/div/form/div[1]/input"));
// secret_eth.sendKeys("0");
WebElement submit_eth = driver.findElement(
By.xpath("//*[#id=\"VerifyTwoFA\"]/div/div/div/app-verify-twofactor/div/div/form/div[2]/button"));
submit_eth.click();
Thread.sleep(2000);
Alert alert_eth = driver.switchTo().alert();
alert_eth.accept();
// clear the fields
WebElement ethvolumeclear =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[1]/input"));
ethvolumeclear.clear();
WebElement ethwalletclear =
driver.findElement(By.xpath("//*[#id=\"wrapper\"]/div[1]/div/div/div[1]/div/div[3]/form/div[2]/input"));
ethwalletclear.clear();
}
public static void main(String[] args) throws InterruptedException {
ether();
login_and_widthdrawl();
}
}
not sure why it s happening, try this to know actual problem:-
public static void main(String[] args) throws InterruptedException {
try{
ether();
login_and_widthdrawl();
}catch(Exception e){
e.printStackTrace();
}
}
Related
I am trying to inspect elements on the webpage but as soon as popup comes it shows an error of element not visible.
I am using correct locators for the same, also I tried using different timeouts for the thread.
Sleep it is not working.
When I click on view source it is showing the same frame as well.
I wrote the below code:
\\\
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class INDIALENDS {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://indialends.com/");
driver.manage().window().maximize();
String s=driver.getCurrentUrl();
System.out.println(s);
driver.getTitle();
String x=driver.getTitle();
System.out.println(x);
\\\
\\\
driver.findElement(By.linkText("Personal Loan")).click();
driver.findElement(By.name("li_display_name")).sendKeys("RAVNEET KAUR");
driver.findElement(By.id("email")).sendKeys("ravneetkaur#indialends.com");
driver.findElement(By.name("pincode")).sendKeys("122018");
driver.findElement(By.id("employment")).click();
Thread.sleep(5000);
driver.findElement(By.id("salaried12")).click();
Thread.sleep(5000);
driver.findElement(By.id("companyName")).sendKeys("INDIALENDS");
Thread.sleep(10000);
driver.findElement(By.id("monthlyIncome")).sendKeys("34000");
driver.findElement(By.id("mobile")).sendKeys("5282273663");
driver.findElement(By.id("li_submit")).click();
Thread.sleep(5000);
\\\
\\\
Thread.sleep(25000);
driver.findElement(By.id("li_submit")).click();
Thread.sleep(25000);
//new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.id("control__indicator")));
driver.findElement(By.id("li_agree")).click();
String s2=driver.getCurrentUrl();
\\\
\\\
System.out.println(s2);
driver.getTitle();
String x1=driver.getTitle();
System.out.println(x1);
Thread.sleep(5000);
}
}
\\\
This the full code. Please try it from your end.
public class MyTesting {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "F:\\Swaroop\\ChromeVersion87\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://indialends.com/");
driver.manage().window().maximize();
String s = driver.getCurrentUrl();
System.out.println(s);
driver.getTitle();
String x = driver.getTitle();
System.out.println(x);
driver.findElement(By.linkText("Personal Loan")).click();
driver.findElement(By.name("li_display_name")).sendKeys("RAVNEET KAUR");
driver.findElement(By.id("email")).sendKeys("ravneetkaur#indialends.com");
driver.findElement(By.name("pincode")).sendKeys("122018");
driver.findElement(By.id("employment")).click();
Thread.sleep(5000);
driver.findElement(By.id("salaried12")).click();
Thread.sleep(5000);
driver.findElement(By.id("companyName")).sendKeys("INDIALENDS");
Thread.sleep(10000);
driver.findElement(By.id("monthlyIncome")).sendKeys("34000");
driver.findElement(By.id("mobile")).sendKeys("5282273663");
driver.findElement(By.id("li_submit")).click();
Thread.sleep(5000);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("control-indicator"))).click();
String s2 = driver.getCurrentUrl();
System.out.println(s2);
driver.getTitle();
String x1 = driver.getTitle();
System.out.println(x1);
Thread.sleep(5000);
}
}
trying to get selenium working but didn't work and showing me below error.
Libs:junit4.12, selenium-java-3.4, selenium-server-standalone-3.5
Could anyone take a look and tell me whats wrong with the code or what is
missing, please.
Every time when I start the test, I get 2 errors.
Screenshot embedded at the bottom showing the error details.
My code as below:
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class TestCase16 {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "URL";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("URL");
}
#Test
public void testCaseAcandoIntranet() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("IDToken1")).clear();
driver.findElement(By.id("IDToken1")).sendKeys("XXX");
driver.findElement(By.id("IDToken2")).clear();
driver.findElement(By.id("IDToken2")).sendKeys("*XXX");
driver.findElement(By.name("Login.Submit")).click();
driver.findElement(By.id("yui_patched_v3_18_1_1_1502961326988_317")).click();
driver.findElement(By.xpath("//a[#id='_com_liferay_product_navigation_user_personal_bar_web_portlet_ProductNavigationUserPersonalBarPortlet_sidenavUserToggle']/span/div")).click();
driver.findElement(By.linkText("Abmelden")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
`
The problem is you are initializing webdriver instance two times like below. specially you have missed specifying the System.setProperty for the first instance of webdriver where exactly your code is failing:-
driver = new FirefoxDriver(); // 1st instance
baseUrl = "URL";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(); // 2nd instance
driver.get("URL");
Now delete above two lines and write your code like below :-
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ayre1de\\Downloads\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("URL");
package testPackage;
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;
import org.testng.annotations.*;
public class AllLinkVerificationInAPage {
WebDriver driver;
#BeforeTest
public void OpenApp()
{
System.setProperty("webdriver.chrome.driver", "E:/Selenium/Webdriver /Softwares/chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("http://ndtv.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement popUp = driver.findElement(By.xpath("//*[#id='__cricketsubscribe']/div[2]/div[2]/a[1]"));
popUp.click();
}
#Test
public void clickLinks() throws InterruptedException
{
//extract the list of WenElements and its count
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
int count = linkElements.size();
System.out.println("Total number of links = " + count );
//test each link
for(WebElement currentElement : linkElements)
{
String link = currentElement.getText();
System.out.println(link);
if(link !="")
{
currentElement.click();
System.out.println("Working Fine");
}
driver.navigate().back();
Thread.sleep(3000);
}
}
}
When I run this code I get following error:-
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document
I tried with implicit wait as well but getting same issue.
Each time the DOM is changed or refreshed, like in going to different page, the driver loses the elements it previously located. You need to relocate the list each iteration
int count = driver.findElements(By.tagName("a")).size();
for (int i = 0 ; i < count ; ++i) {
List<WebElement> linkElements = driver.findElements(By.tagName("a"));
WebElement currentElement = linkElements.get(i);
String link = currentElement.getText();
System.out.println(link);
if(link != "")
{
currentElement.click();
System.out.println("Working Fine");
}
driver.navigate().back();
Thread.sleep(3000);
}
Can someone help with it ?
I have error
"Exception in thread “main” org.openqa.selenium.StaleElementReferenceException: Element not found in the cache"
Why showing this error?
I need to hover on each category menu than click on each text in sub-menu.
public class santander {
private static WebDriver driver = null;
public static JavascriptExecutor js = (JavascriptExecutor) driver;
public static void main(String[] args) throws FileNotFoundException, InterruptedException, IOException {
// TODO Auto-generated method stub
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.santander.co.uk/uk/index");
driver.manage().window().maximize();
driver.get("http://www.santander.co.uk/uk/index");
JavascriptExecutor js = (JavascriptExecutor) driver;
WebDriverWait wait = new WebDriverWait(driver, 10);
String submenutxtlinks = "submenu.txt";
List<String> submenu = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(submenutxtlinks));
String line;
while ((line = reader.readLine()) != null) {
submenu.add(line);
}
reader.close();
Actions action = new Actions(driver);
/*
WebElement menu = driver.findElement(By.linkText("Current Accounts"));
action.moveToElement(menu).perform();
WebElement submenu = driver.findElement(By.linkText("See all current accounts"));
action.moveToElement(submenu);
action.click();
action.perform();
*/
// String title = driver.getTitle();
// wait.until(ExpectedConditions.titleIs(title));
// driver.navigate().back();
//Loop to read all lines one by one from file and print It.
// while((menu = BR.readLine())!= null && !menu.isEmpty()){
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Action hovering = action.moveToElement(a).build();
// hovering.perform();
//action.moveToElement(a).perform();
//action.clickAndHold(a).perform();
WebElement a = driver.findElement(By.cssSelector("#nav > div.navMain > div.nav_menu > nav > ul > li:nth-child(1) > a"));
Action hovering = action.moveToElement(a).build();
//Thread.sleep(2000);
for (int i=0;i<=submenu.size()-1;i++ ) {
//String b = submenu.get(i);
// System.out.println(b);
//WebElement b = driver.findElement(By.xpath(submenu.get(i)));
try{
//Your code which causes exception
hovering.perform();
//action.moveToElement(b).click(b).build().perform();
Thread.sleep(1000);
clickAnElementByLinkText(submenu.get(i));
//b.click();
Thread.sleep(1000);
/*
wait.until(ExpectedConditions.visibilityOf(b));
action.moveToElement(b);
action.click();
action.perform();
*/
// wait.until(ExpectedConditions.titleIs(title));
driver.navigate().back();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Thread.sleep(2000);
// driver.get("http://www.santander.co.uk/uk/index");
//driver.navigate();
Thread.sleep(2000);
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
catch(org.openqa.selenium.StaleElementReferenceException e){
//Repeat the code in try
}
}
// }
driver.close();
}
public static void clickAnElementByLinkText(String linkText) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(linkText)));
driver.findElement(By.xpath(linkText)).click();
}
}
Dont mix ImplicitWait ExplicitWait and Thread.Sleep all in the same context.
Learn when and where those should be used.
The hoverElement wont work because the driver navigates to different page and element no longer exists you have find it again inside the forLoop
For the sake of test I've hardcoded the submenulist
This code will do what you've asked for
import java.util.ArrayList;
import java.util.Arrays;
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;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ListTest {
static WebDriver driver;
public static void main(String[] args) {
List<String> submenu = new ArrayList<>(Arrays.asList(new String[]{"See all current accounts", "1|2|3 Current Account", "Everyday Current Account", "Basic Current Account", "Choice Current Account"}));
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.santander.co.uk/uk/index");
for (String sMenu : submenu) {
WebElement a = driver.findElement(By.cssSelector("#nav > div.navMain > div.nav_menu > nav > ul > li:nth-child(1) > a"));
new Actions(driver).moveToElement(a).build().perform();
clickAnElementByLinkText("//li[#role='listitem']/a[normalize-space(text())='" + sMenu + "']");
driver.navigate().back();
}
driver.quit();
}
public static void clickAnElementByLinkText(String linkText) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(linkText))).click();
}
}
You are trying to access an element which does not exists.
The code collects the elements on the page,
then the code clicks an element which changes the source
then it try to access an object he collected before but it is not longer there (what you see is a new one).
You can enter the finding of the elements process into the loop and loop changing the 'i' element in every iteration (If you must click the element in every iteration).
i am getting somthing like this
Hi i am scraping a web page using Selenium Webdriver an i am able to achieve my data but problem is that this directly interact with browser and i dont want to open a web browser and want to scrape all data as it is
How can i achieve my goal
Here is my code
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class GetData {
public static void main(String args[]) throws InterruptedException {
String sDate = "27/03/2014";
WebDriver driver = new FirefoxDriver();
String url="http://www.upmandiparishad.in/commodityWiseAll.aspx";
driver.get(url);
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
// click buttonctl00_ContentPlaceHolder1_txt_rate
Thread.sleep(3000);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(5000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
}
}
My updated New code
import com.gargoylesoftware.htmlunit.BrowserVersion;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
public class Getdata1 {
public static void main(String args[]) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
driver.get("http://www.upmandiparishad.in/commodityWiseAll.aspx");
System.out.println(driver.getPageSource());
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
String sDate = "12/04/2014"; //What date you want
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(3000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
}
}
Thanks in advance
Use HtmlUnit or HtmlUnitDriver by Selenium
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_17);
driver.get("http://www.upmandiparishad.in/commodityWiseAll.aspx");
System.out.println(driver.getPageSource());
Thread.sleep(5000);
// select barge
new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
String sDate = "12/04/2014"; //What date you want
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDate);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(3000);
//get only table tex
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
String htmlTableText = findElement.getText();
// do whatever you want now, This is raw table values.
System.out.println(htmlTableText);
driver.close();
driver.quit();
To get tabular output, you can try something like this..
String arrCells[] = htmlTableText.split(" ");
Boolean bIsANumber = false;
for(int i = 0; i < arrCells.length; i++) {
try {
int tmp = Integer.parseInt(arrCells[i]);
bIsANumber = true;
}
catch(Exception ex) {
bIsANumber = false;
}
if(bIsANumber) {
System.out.print("\n"+arrCells[i]+"\t");
}
else {
System.out.print(arrCells[i]+"\t");
}
}