使用selenium遇到java.lang.NoSuchMethodError: org.apache.xpath.XPathContext,排查

初试selenium webdriver,运行小程序,抛如下错误:
 

1
2
3
4
5
6
7
8
9
10
11
java.lang.NoSuchMethodError: org.apache.xpath.XPathContext.< init >(Z)V
      at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:115)
      at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)
      at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)
      at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:120)
      at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:60)
      at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
      at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:416)
      at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:394)
      at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:89)
      at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
 
google后检索到:https://code.google.com/p/selenium/issues/detail?id=2837
 
xalan.jar冲突导致,排除此包后ok.
 
   
 
注意下selenium的包引用,如果尝试用webdriver +java去运行用例,并不需要selenium-server这个jar包。根据官网文档,当使用Selenium-Grid将用例在多个机器或者虚拟机上执行, or 远程执行用例等情况才使用。
 
练习时可以直接引入 selenium-java 即可。 如果是maven工程,直接在pom.xml中引入如下依赖即可(可在官网查询最新版本的)
1
2
3
4
5
< dependency >
   < groupId >org.seleniumhq.selenium groupId >
   < artifactId >selenium-java artifactId >
   < version >2.42.2 version >
dependency >
或者在pom.xml中去除版本依赖

		jaxen
		jaxen
		
			
				xalan
  				xalan
			
		
	


你可能感兴趣的:(架构设计)