Selenium webdriver Selenium 2示例不起作用

Selenium webdriver Selenium 2示例不起作用,selenium-webdriver,Selenium Webdriver,我已经在上一次学习了这个例子 package net.qaautomation.examples; 导入org.openqa.selenium.By; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.firefox.FirefoxDriver; 导入org.openqa.selenium.support.ui.ExpectedCondition; 导入org.openqa.selenium.support.ui.Wait; 导入or

我已经在上一次学习了这个例子

package net.qaautomation.examples;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.support.ui.ExpectedCondition;
导入org.openqa.selenium.support.ui.Wait;
导入org.openqa.selenium.support.ui.WebDriverWait;
/**
*搜索谷歌的例子。
*
*@作者拉胡尔
*/
公共类谷歌搜索{
静态网络驱动程序;
静态等待;
公共静态void main(字符串[]args){
驱动程序=新的FirefoxDriver();
等待=新的WebDriverWait(驱动程序,30);
驱动程序。获取(“http://www.google.com/");
布尔结果;
试一试{
结果=firstPageContainsQAANet();
}捕获(例外e){
e、 printStackTrace();
结果=假;
}最后{
driver.close();
}
System.out.println(“测试”+(结果?“通过”。:“失败”);
如果(!结果){
系统出口(1);
}
}
私有静态布尔值firstPageContainsQAANet(){
//类型搜索查询
driver.findElement(By.name(“q”)).sendKeys(“qa自动化”);
//单击搜索
driver.findElement(By.name(“btnG”))。单击();
//等待搜索完成
等待.直到(新的ExpectedCondition(){
公共布尔应用(WebDriver WebDriver){
System.out.println(“搜索…”);
返回webDriver.findElement(By.id(“resultStats”)!=null;
}
});
//在结果中查找QAAutomation.net
返回driver.findElement(按.tagName(“body”)).getText()包含(“qaautomation.net”);
}
}

但当我运行它时,我得到了错误

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:48)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:120)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:81)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at com.google.gwt.sample.contacts.test.GoogleSearch.main(GoogleSearch.java:20)
线程“main”java.lang.NoSuchMethodError中出现异常:org.apache.http.conn.scheme.scheme。(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V 位于org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59) 位于org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:48) 位于org.openqa.selenium.remote.HttpCommandExecutor。(HttpCommandExecutor.java:120) 位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:81) 位于org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244) 位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:110) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) 位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:183) 位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:179) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) 位于com.google.gwt.sample.contacts.test.GoogleSearch.main(GoogleSearch.java:20) 有什么想法可能是错误的吗?事实上,我尝试过的其他几个例子都给了我一个类似的NoSuchMethod错误。如
如果您有任何简单的Selenium2示例,我将非常感谢您提供链接。Thnx

如果您想开始使用seleniumhq.org上的seleniumhq.org文档,我建议您通读一下,或许可以尝试下一页上的示例,它稍微简化一点


我还建议您使用eclipse,在掌握webdriver之前不要使用maven和ant,这是假设您是这些应用程序的新手。

我不使用maven或ant,只是更愿意自己做任何事情,以便更好地理解它们。我使用的是Eclipse,并且已经导入了所有必需的JAR,但仍然得到相同的错误。不清楚在没有任何评论的情况下,对这个问题的否决票是为了什么:(考虑到我一直在浏览文档,最终你必须做一个例子,我有问题的是这个例子,而不是文档你的程序第20行有什么内容?从这个例子来看,它是“driver=new FirefoxDriver();”你也一样吗?是的,FirefoxDriver()。我将发布我的代码以确保完整性,但它与我发布的链接相同。我复制了你的代码并亲自运行,它工作正常。你确定你将Selenium jar正确添加到构建路径中了吗?我使用了Selenium-2.28.0,并将其替换为Selenium-2.29.0中的jar,它现在工作正常。不确定是什么问题他对v28存在问题,但我没有时间进行适当的调查。当我将v28 JAR放回时验证,它再次失败,因此它与Selenium版本有关:(
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:48)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:120)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:81)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
at com.google.gwt.sample.contacts.test.GoogleSearch.main(GoogleSearch.java:20)