0

Hi i am trying to scrape data of a site i did code for that i want to scraoe data on button click event but when i run my program it throws exception

Exception is: java.lang.NoClassDefFoundError: com/google/common/base/Function

How can i remove this exception and work my program

Here is my code which i tried

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 {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.upmandiparishad.in/commodityWiseAll.aspx");
        Thread.sleep(5000);
        // select barge
        new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
        // click button
        Thread.sleep(3000);
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
        Thread.sleep(5000);

        //get only table tex
        WebElement findElement = driver.findElement(By.className("grid-view"));
        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

user3456343
  • 252
  • 3
  • 7
  • 21

1 Answers1

0

Hope this will help you..

    //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);

    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);
Nadun
  • 300
  • 4
  • 15
  • how can i get genrated web page? – user3456343 Apr 02 '14 at 07:53
  • Sorry I forget the **;** `String sDate = "12/04/2014";` With these fixing it is working.. I tried.. – Nadun Apr 02 '14 at 07:53
  • Use `String.split(" ")`. Split by ; `String arrRowData[] = htmlTableText.split("\n"); for(int i = 0; i < arrRowData.length(); i++){ String arrCellData[] = arrRowData[i].split(" "); for(int j = 0; j < arrCellData.length(); j++) { sout(arrCellData[j]);}}` – Nadun Apr 02 '14 at 08:03
  • dear can u tell me without opneing browser how can i get same data – user3456343 Apr 02 '14 at 09:01
  • Try **HtmlUnitDriver** – Nadun Apr 02 '14 at 09:06
  • Put `WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_17);` or what ever your firefox version instead of `WebDriver driver = new FirefoxDriver();` Table data layout may be bit different. Hope you can figure it out..In-case to debug put `System.out.println(driver.getPageSource());` after `driver.get(sURL);` – Nadun Apr 02 '14 at 09:18
  • i made change but throwing exception – user3456343 Apr 02 '14 at 09:21
  • This may help you : http://stackoverflow.com/questions/19139151/htmlunitdriver-does-not-appear-to-be-loading-page – Nadun Apr 02 '14 at 09:22