Solution for XHR ERROR: Response_Code = -1 Error_Message = Request Error

Problem: When trying to open a URL using Selenium RC 1.0.3 with Firefox 3.6, the following error is reported through the server log:

XHR ERROR: Response_Code = -1 Error_Message = Request Error
after which the browser windows disappear and the session is aborted. Interestingly, this only happens when trying to access remote sites, not sites from localhost.

Workaround: This error seems to be caused by something in the Firefox profile template provided with option -firefoxProfileTemplate. I temporarily edited selenium-browserbot.js within the selenium-server.jar to make it ignore the error (new line highlighted in red):

    this.isNewPageLoaded = function() {
        if (this.pageLoadError) {
            LOG.error("isNewPageLoaded found an old pageLoadError");
            var e = this.pageLoadError;
            this.pageLoadError = null;
            throw e;
        }

        if (self.ignoreResponseCode) {
            return self.newPageLoaded;
        } else {
            if (self.isXhrSent && self.isXhrDone) {
                if (self.xhrResponseCode == -1) return self.newPageLoaded;
                if (!((self.xhrResponseCode >= 200 &&
                    self.xhrResponseCode <= 399) ||
                    self.xhrResponseCode == 0)) {

With this change, the error ceased to be reported. I could no longer reproduce the problem later after removing this temporary fix.

9 comments:

Tina said...

Thanks a lot for your tip! I tried to add the code that you suggested but I ran into a problem...

I extracted the Selenium-server.jar with command: jar xvf selenium-server.jar

Then I edited the file selenium-browserbot.js as you described. Then I created a jar again with the command: jar cvf selenium-server.jar.

When I started the server I received following error: "Failed to load Main-Class manifest attribute from selenium-server.jar"

Do you have any idea what the problem is?

jpl said...

When you re-create the JAR file with jar (rather than, say, with WinZip), you must not forget to name the old manifest file using an extra parameter, eg.

jar cmvf META-INF/MANIFEST.MF selenium-server.jar

The file MANIFEST.MF contains the Main-Class line which instructs the Java VM which class should be taken as application entry point when you use the command "java -jar xxxx.jar". If you forget the 'm' option while creating a jar file, it will generate a new empty MANIFEST.MF without the Main-Class attribute.

Tobias said...

Thanks! This solved my problem.

I had to run this command in order to get the jar back together:

jar cmvf META-INF/MANIFEST.MF selenium-server.jar -C selenium-jar (this is the location where i unjared the selenium-server.jar)

RonDav said...

Hello
We tried to use this workaround:
if (self.xhrResponseCode == -1) return self.newPageLoaded;

The only difference was that we didn't see the error message, but the error still happened
The browser dissconnected from selenium
Any other ideas?
Can u explain the cause of failure?
Thnaks in advance
Ron

jpl said...

Ron, I haven't got more information besides of what is already included in the post. I've since upgraded to FF4 and Selenium 2.0b3 for my testing, and this problem didn't reappear (although there was another one concerning unsuppressed window.alarm popups; "issue 27", for which a patch is now available).

Anonymous said...

Hi all, i'm trying to use "jar cmvf META-INF/MANIFEST.MF selenium-server.jar -C MyDirPreviouslyUnjared" but it doesn't work.
Can you help me to solve the problem? Which is the correct syntax of the command?
Thanks a lot.

jpl said...

@Anonymous how about this:

cd MyDirPreviouslyUnjared
jar cmvf META-INF/MANIFEST.MF selenium-server.jar *

Anonymous said...

Thanks jpl. Today i will try the new server.

Sreedhar Velagapudi said...

Thank You Jan Ploski,

This article helped us. We also added another condition for IE in the same .js file before making an updated jar. "if (self.xhrResponseCode == -1 || self.xhrResponseCode == 12007)"

Thanks

Post a Comment