NoClassDefFoundError: org/apache/http/HttpEntity in Selenium for ChromeDriver?

前端 未结 2 1147
夕颜
夕颜 2020-12-12 02:01

i am trying to fetch data from a website using Selenium automation when i am trying to access data from that web site i am getting following exception

run         


        
相关标签:
2条回答
  • 2020-12-12 02:16

    To check your code I tried the following:

    @Test
    public void test1() throws Exception {
        System.setProperty("webdriver.chrome.driver", "t:\\Others\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
    
        String url = "http://www.upmandiparishad.in/commodityWiseAll.aspx";
    
        driver.get(url);
        Thread.sleep(5000);
    
        new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Paddy");
        Thread.sleep(5000);
    
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys("27/03/2014");
        Thread.sleep(5000);
    
        driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
        Thread.sleep(5000);
    
        driver.close();
    

    }

    It works fine with FireFox (29.0) and Chrome (34.0) drivers. I used the following jar-s:

    • selenium-server-standalone-2.41.0.jar
    • selenium-java-2.41.0.jar
    • junit-dep-4.11.jar
    • hamcrest-core-1.3.jar

    You should check your project build path and add the appropriate jar-s. But you can find the missing class file in the selenium-server-standalone-2.XY.0.jar if you open it: selenium-server-standalone-2.41.0.jar\org\apache\http\entity\ContentType

    Another way is to use httpcore.jar (httpcore-4.3.jar) that contains the missing class file.

    0 讨论(0)
  • 2020-12-12 02:29

    This is actually because you are using old version of the selenium java binding, i guess lower than 2.40.0 as this selenium version is missing org/apache/http/entity/ContentType (itself internally)

    so there are two solutions to it.

    Option 1- You wish to keep selenium 2.40.0 or lower

    If you wish of keeping the old selenium 2.40.0 or lower then you have to add missing jar to your project yourself, if you are using maven below is the dependency.

    <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
                <version>4.3</version>
    </dependency> 
                         or 
    

    link to download the hhtpcore 4.3 jar

    Option 2- You can update the old selenium 2.40.0 or lesser to 2.53.0 or latest 3.4.0

    Please update to a new selenium version like selenium 2.53.0 or latest Selenium 3.4.0

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>
    

    link for the selenium jar 2.53.0

                        **or** 
    
     <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
    
    0 讨论(0)
提交回复
热议问题