我正在尝试使用Selenium网络驱动程序上传文件。以上错误收到。我知道代码还可以。大多数帖子都说这是因为“依赖”。我该如何解决?我检查了没有相同名称的jar文件。这里我展示了我的jar文件的一些屏幕截图。我该如何解决这个依赖性问题?
Java代码:
import java.io.File;
import java.io.IOException;
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.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class FusekiStart {
public static void main(String[] args) {
/* Selenium config */
String PROXY = "localhost:3030";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(cap);
driver.get("http://localhost:3030/control-panel.tpl");
driver.findElement(By.xpath("//input[@value='Select']")).click();
driver.findElement(By.xpath("//input[@type='file']")).sendKeys("C:\\Users\\user1\\Desktop\\Ontology.owl");
driver.findElement(By.xpath("//input[@value='Upload']")).click();
}
}
错误讯息:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init> (DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:68)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:55)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:99)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:82)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:93)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
at uom.brts.statisticalmt.FusekiStart.main(FusekiStart.java:39)
答案 0 :(得分:0)
检查此链接: Source Code at Grep
您缺少org.apache.http.message包中的BasicLineFormatter类。
答案 1 :(得分:0)
我会说这不会解决您的问题,但是您可以通过包含一个httpcore 4.2.2 jar文件来查看您当前正在使用的文件。您是否可以尝试从Link获取更高的值并将其替换为当前的httpcore 4.2.2,看看它有什么不同?
答案 2 :(得分:0)
我遇到了同样的问题。经过大量调试后,我发现存在CLASSPATH冲突。项目中已存在的jar文件
httpclient-osgi-4.2.1.jar
与selenium jar文件冲突。对我来说幸运的是,项目中不再需要httpclient-osgi-4.2.1.jar文件,因此我可以安全地删除它。之后问题就消失了。
错误信息很可悲。它无论如何都无助于指出真正的问题。