Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Selenium 2 FirefoxDriver "NoSuchMethodError: org.apache.xpath.XPathContext" #2837

Closed
lukeis opened this issue Mar 3, 2016 · 24 comments
Closed

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 2837


When using "new FirefoxDriver()" I am always getting a "NoSuchMethodError: org.apache.xpath.XPathContext".

For information InternetExplorerDriver works fine.

What steps will reproduce the problem?
1. Create an empty Java project in Eclipse
2. Create a simple class to test the FirefoxDriver 
---> *** please see the attached file for the sample test. ***
---> *** please see the attached project's .classpath ***
4. Run the test as a Java Application
5. The full error is :

Exception in thread "main" 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:121)
    at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61)
    at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
    at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:547)
    at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:525)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:78)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:79)
    at com.selenium.GoogleSuggest.main(GoogleSuggest.java:14)

What is the expected output? What do you see instead?
FirefoxDriver should not fail.

Selenium version: 2.12.0
OS: Windows 7 32-bit
Browser: Firefox 
Brower version: 5.0

Please don't hesitate if you need more information.

Many thanks.

Reported by mark.kiami on 2011-11-14 17:04:02


- _Attachment: [GoogleSuggest.java](https://storage.googleapis.com/google-code-attachments/selenium/issue-2837/comment-0/GoogleSuggest.java)_ - _Attachment: [.classpath](https://storage.googleapis.com/google-code-attachments/selenium/issue-2837/comment-0/.classpath)_
@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For information, I am not using maven for this sample project. 
I have just manually included the jars listed in the attached .classpath file.

Reported by mark.kiami on 2011-11-14 17:05:28

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by barancev on 2011-11-14 17:52:08

  • Labels added: Component-WebDriver, Browser-Firefox, Lang-Java

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

What if you remove selenium-firefox-driver-2.12.0.jar and selenium-htmlunit-driver-2.12.0.jar
from the classpath?

Reported by barancev on 2011-11-14 18:45:49

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

After removing those 2 jars (selenium-firefox-driver-2.12.0.jar and selenium-htmlunit-driver-2.12.0.jar),
there were no compilation errors though, so there was no need for them anyway, but
I'm having the same issue even after removing them from the classpath.

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.xpath.XPathContext.<init>(Z)V





Reported by mark.kiami on 2011-11-15 08:45:38

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For info, the full error after removing the 2 jars is :

Exception in thread "main" 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:121)
    at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61)
    at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
    at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:547)
    at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:525)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:78)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:79)
    at com.selenium.GoogleSuggest.main(GoogleSuggest.java:14)

Reported by mark.kiami on 2011-11-15 09:03:38

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

How do you run selenium -- from IDE or console?
How do you know it uses exactly this classpath file, not some other?

Please run the following snippet of the code in your test file:

System.out.println(new XPathContext().getClass().getProtectionDomain().getCodeSource().getLocation());

Does it print the correct path to selenium-server-standalone-2.12.0.jar (where XPathContext
should be loaded from)?

Reported by barancev on 2011-11-15 16:02:53

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

- The selenium test is run form the Eclipse IDE : right click on the test class the
Run As / Java Application.

- I am not sure which classpath is used, the .classpath file attached is the one associated
with this Eclipse project.

- When trying System.out.println(new XPathContext().getClass().getProtectionDomain().getCodeSource().getLocation());
   I had to import org.apache.xpath.XPathContext in the test file
   I am getting a NullPointerException on the "getLocation()" part :

   Exception in thread "main" java.lang.NullPointerException


Reported by mark.kiami on 2011-11-15 16:35:58

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I forgot to attach the screenshot of the project's build path in Eclipse, notice that
xalan.jar is already part of the Java SE 1.6. 

Reported by mark.kiami on 2011-11-15 16:51:38

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by mark.kiami on 2011-11-15 16:52:15


- _Attachment: eclipse_classpath.png
![eclipse_classpath.png](https://storage.googleapis.com/google-code-attachments/selenium/issue-2837/comment-9/eclipse_classpath.png)_

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Great, it explains the issue! getCodeSource() == null means that the code was loaded
from the standard library. And your screenshot commits this.

Selenium standalone server includes Xalan too, and probably a different version of
it.

To aloid collisions you have to either remove endorsed libraries from the standard
libraries, or use a set of libs instead of all-in-one standalone server. Download selenium-java-2.12.0.zip
and add to your classpath only required dependencies (or you may use maven repository
too, probably).

Reported by barancev on 2011-11-15 18:16:30

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

There was no way to make the simple selenium test run with FirefoxDriver.
I have tried : 
- Using the jars from selenium-java-2.12.0.zip
- Using the individual jars from the maven "selenium-java" (selenium-firefox-driver-2.12.0.jar,
selenium-api-2.12.0.jar, selenium-remote-driver-2.12.0.jar, etc...)

None of them resolved the issue, I am still getting the same error :

Exception in thread "main" 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:121)
    at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61)
    at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
    at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:547)
    at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:525)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:78)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:79)
    at com.selenium.GoogleSuggest.main(GoogleSuggest.java:20)

For information, ChromeDriver and InternetExplorerDriver both work fine.

I've noticed that some had the same issue by searching a little, but no one explained
how they resolved this issue...

Reported by mark.kiami on 2011-11-16 09:38:12

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Can anyone create this simple project in Eclipse and try to reproduce the error ?

The .java and .classpath were both previously attached. This would be of huge help.

Reported by mark.kiami on 2011-11-16 09:42:10

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

The file .classpath is not the matter of the issue, the collision caused by your local
JRE installation. Remove jar files from the 'endorsed' subdir of JRE installation location
and check again, it should resolve the issue.

Reported by barancev on 2011-11-16 11:15:10

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

This solved the issue, thanks barancev !

For information, I had to remove 2 jars from C:\Program Files\Java\jre6\lib\endorsed
:
- xalan.jar, which created the previous NoSuchMethodError
- xml-api.jar, which created the following error :

Exception in thread "main" java.lang.NoSuchMethodError: org.w3c.dom.Node.getTextContent()Ljava/lang/String;
    at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:134)
    at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:61)
    at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
    at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:547)
    at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:525)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:74)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:78)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:79)
    at com.selenium.GoogleSuggest.main(GoogleSuggest.java:20)


Moreover, is it safe to remove jars from the default JRE endorsed directory ?
I mean these jars come from the standard Java installation, won't this break anything
?

Reported by mark.kiami on 2011-11-16 11:41:27

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

There jars don't come with JRE, they were added separately (for some reasons you or
your collegues should now better :))

Reported by barancev on 2011-11-16 14:03:02

  • Status changed: WorkingAsIntended

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I too had an issue similar to above one. My project was using two versions of xalan,
xalan-2.6.0 and xalan-2.7.1. When removed xalan-2.6.0 it started working properly.

Reported by kuruvila.mathew on 2011-11-21 16:42:11

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I have also resolved the issue by removing an outdated xalan. In my case, I got a version
2.4.1 xalan which can be found at the projects tab in "Java Build Path".

Name: org/apache/xalan
Comment: Main Xalan engine implementing TrAX/JAXP
Specification-Title: Java API for XML Processing
Specification-Vendor: Sun Microsystems Inc.
Specification-Version: 1.1
Implementation-Title: org.apache.xalan
Implementation-Version: 2.4.1
Implementation-Vendor: Apache Software Foundation
Implementation-URL: http://xml.apache.org/xalan-j/dist/

you may use debugger on the junit test case pause a thread, right click on the thread
and select "properties".
under the "command line" section, the classpath for the debugging session can be found.
Search xalan and you'll find out what are the copies there.

Reported by tealeeseng on 2012-01-12 10:56:57


- _Attachment: debugThreadProperties.png
![debugThreadProperties.png](https://storage.googleapis.com/google-code-attachments/selenium/issue-2837/comment-17/debugThreadProperties.png)_

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks barancev!,

 I do face the same issue after removing xalan.jar from my class path, the problem
went away, but not sure why including xalan is causing this issue and that jar is required
by some other classes in my project.

Reported by venkatpersonal9 on 2012-01-27 01:12:17

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I am using selenium2.17.0  and I am getting the same issue. There's no endorsed folder
in my java/jdk/jre location (checked all). Please help.
One more thing, a old project works fine, but creating a new project doesn't although
both share the same jars.

Reported by nitin.cool4urchat on 2012-03-07 14:37:09

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

it works!!!!!!!!!!! yeeeeees!!! thankyou!!!:)

Reported by mdacal82 on 2012-06-29 09:41:24

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Thanks a lot...removing xalan.jar solved my issue.

Reported by pushpabadennavar.cogbooks on 2013-09-11 06:36:32

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Just in case you are using an eclipse + maven combination, the issue is solved if you
put your selenium-server-standalone-x.x.x.jar _above_ your Maven dependencies (above
is in before) in your project's "Order and Export" in the "Configure Build Path" section
of your project's settings.

Reported by mikeplautz on 2014-12-05 02:07:12

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

removing xalan.jar solved my issue

Reported by prabhat.sikar on 2014-12-07 04:51:12

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:14:09

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant