首页 > 代码库 > 使用selenium遇到java.lang.NoSuchMethodError: org.apache.xpath.XPathContext,排查

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

处试selenium webdriver,运行小程序,抛如下错误:
 
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中引入如下依赖即可(可在官网查询最新版本的)
<dependency>  <groupId>org.seleniumhq.selenium</groupId>  <artifactId>selenium-java</artifactId>  <version>2.42.2</version></dependency>