大佬教程收集整理的这篇文章主要介绍了NoClassDefFoundError:Selenium中的org / apache / http / HttpEntity for ChromeDriver吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为了检查您的代码,我尝试了以下操作:
@H_607_4@@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();
}
它可以与firefox(29.0)和Chrome(34.0)驱动程序正常工作。我使用了以下jar-s:
您应该检查项目的构建路径并添加适当的jar。但是,如果打开它,则可以在SELEnium-server- standalone-2.XY.0.jar中找到丢失的类文件:SELEnium-server-standalone-2.41.0.jar \ org \ apache \ http \ entity \ ContentType
另一种方法是使用包含缺少的类文件的httpcore.jar(httpcore-4.3.jar)。
当我尝试从该网站访问数据时,我尝试使用SELEnium自动化从网站中获取数据
@H_607_4@run:
StarTing ChromeDriver (v2.9.248315) on port 15621
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/entity/ContentType
at org.openqa.SELEnium.remote.httpCommandExecutor$EntityWithEncoding.<init>(httpCommandExecutor.java:411)
at org.openqa.SELEnium.remote.httpCommandExecutor.execute(httpCommandExecutor.java:306)
at org.openqa.SELEnium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66)
at org.openqa.SELEnium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568)
at org.openqa.SELEnium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.SELEnium.chrome.ChromeDriver.startSession(ChromeDriver.java:181)
at org.openqa.SELEnium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.SELEnium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139)
at org.openqa.SELEnium.chrome.ChromeDriver.<init>(ChromeDriver.java:160)
at org.openqa.SELEnium.chrome.ChromeDriver.<init>(ChromeDriver.java:149)
at org.openqa.SELEnium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at pOCMandi.POCMandi.main(POCMandi.java:32)
Caused by: java.lang.ClassnotFoundException: org.apache.http.entity.ContentType
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doprivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 12 more
这是我的鳕鱼
@H_607_4@package pOCMandi;
import com.gargoylesoftware.htmlunit.browserVersion;
import java.util.StringTokenizer;
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;
import java.sql.*;
import org.openqa.SELEnium.chrome.ChromeDriver;
public class POCMandi {
Statement st = null;
Connection cn = null;
public static void main(String args[]) throws InterruptedException,ClassnotFoundException,SQLException {
int j = 0;
String htmlTableText = null;
System.setProperty("webdriver.chrome.driver","C:\\Users\\SHAKTI\\Desktop\\JarFiles\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String commodity = "Jo";
String commo[] = {"Paddy","Rice","Jwar","Barley","Corn","Wheat","Jo","Bejhar","Jai","Urad","Moong","Chana","Matar"};
for (String com : commo) {
String sDate = "27/03/2014";
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(com);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txt_rate")).sendKeys(sDatE);
Thread.sleep(3000);
driver.findElement(By.id("ctl00_ContentPlaceHolder1_btn_show")).click();
Thread.sleep(5000);
WebElement findElement = driver.findElement(By.id("ctl00_ContentPlaceHolder1_GridView1"));
// WebElement find=driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"));
htmlTableText = findElement.getText();
// String html=find.getText();
// do whatever you want now,This is raw table values.
htmlTableText = htmlTableText.replace("s.No.DiStrictMarketPrice","");
htmlTableText = htmlTableText.replaceAll("\\s(\\d+\\s[A-Z])","\n$1");
htmlTableText = htmlTableText.replaceAll("(?=(.*?[ ]){4,}).*?[\n\r]","");
htmlTableText = htmlTableText.replace("s.No. DiStrict Market Price","");
System.out.println(htmlTableText);
String s[] = htmlTableText.split("");
StringTokenizer str = new StringTokenizer(htmlTableText);
while (str.hasMoreTokens()) // for(int i=0;i<s.length;i++)
// if(str.hasMoreElements())
{
String no = str.nextElement().toString();
String city = str.nextElement().toString();
String mandi = str.nextElement().toString();
String price = str.nextElement().toString();
Class.forName("com.mysql.jdbc.Driver");
Connection cn = DriveRMANager.getConnection("jdbc:mysql://localhost:3306/mandi","root","");
//insert them into the database
PreparedStatement ps = cn.prepareStatement("insert into commoditydemo values(?,?,?)");
ps.setString(1,no);
ps.setString(2,city);
ps.setString(3,mandi);
ps.setString(4,pricE);
ps.setString(5,com);
ps.setString(6,"0");
j = ps.executeupdate();
cn.close();
}
}
driver.close();
driver.quit();
if (j == 1) {
System.out.println("data inserted");
} else {
System.out.println("not inserted");
}
}
}
如何获取我的输出并删除此异常?
提前致谢
以上是大佬教程为你收集整理的NoClassDefFoundError:Selenium中的org / apache / http / HttpEntity for ChromeDriver吗?全部内容,希望文章能够帮你解决NoClassDefFoundError:Selenium中的org / apache / http / HttpEntity for ChromeDriver吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。