Selenium, XPath and Internet Explorer – Painfully Slow?

I’ve been using RobotFramework with its Selenium Library for web automation for quite a while now and have always had the problem of getting any scripts that use XPath run on Internet Explorer.

For some web applications, if they’re not too complex and don’t use a lot of Ajax, you might be able to run scripts that use XPath on Internet Explorer and actually have them finish in this lifetime. But most of the time, they won’t.
So I googled it. I found out that a lot of other people have googled it and a lot of them have complained on different forums. I’ve also found out that Selenium uses “AJAXSLT” as its default XPath library, which has a lot of performance issues on IE, and that the trick is to change this to the much faster javascript-xpath library.
However, none of the sites I read told me how to do that. I’ve never used Selenium RC directly, I’ve always used the Selenium Library for/from within RobotFramework, so maybe this is a trivial change in Selenium. But for those of you, like me, who are stuck with a “selenium-server.jar” file, here’s what I had to do:
1. Locate “selenium-server.jar” (For RobotFramework users, this will be located in your Python directory, under \Lib\site-packages\SeleniumLibrary\lib\)
2. Make a copy of it (just in case).
3. Rename it to “selenium-server.zip” and unpack it.
4. Browse the unpacked selenium-server folder and go to \core\scripts\.
5. Edit “selenium-browserbot.js”.
6. Inside the file, search for “ajaxslt”. Depending on the version that you have installed, you should find one of the following lines:
this.xpathLibrary = this.defaultXpathLibrary = ‘ajaxslt‘ // change to “javascript-xpath” for the newer, faster engine
or
this.xpathEvaluator = new XPathEvaluator(‘ajaxslt‘); // change to “javascript-xpath” for the newer, faster engine
7. Change this line to:
this.xpathLibrary = this.defaultXpathLibrary = ‘javascript-xpath‘ // change to “ajaxslt” for the slower, older engine
or
this.xpathEvaluator = new XPathEvaluator(‘javascript-xpath‘); // change to “ajaxslt” for the slower, older engine
8. Save the file.
9. Archive the folder again into “selenium-server.zip”
10. Rename it back to “selenium-server.jar”
This worked just fine for me and I now get almost the same run times on Internet Explorer and Firefox. Hope it helps!

Subscribe to our newsletter

And get our best articles in your inbox

 Back to top

19 responses to “Selenium, XPath and Internet Explorer – Painfully Slow?

  1. hi,
    thanks a lot for sharing this.
    I tried it, but after I Archive the folder again into “selenium-server.zip” and rename it to selenium-server.jar i get an error when trying to run it –
    “Invalid or corrupt jarfile selenium-server.jar”.

    any suggestions?

    thanks.

  2. Please make sure you don’t archive the actual folder, but its content.

    So, make sure you go *inside* the “seleium-server” folder, select all the files and folders inside it, then archive all of those into “selenium-server.zip”, change that into “selenium-server.jar” and copy it under \Lib\site-packages\SeleniumLibrary\lib\

    That should work just fine. If you still have problems, please let me know.

    Ru

  3. hi,
    maybe you can help – I’m trying to use selenium with xpath to activate a link on the page(locator).

    this is basically the HTML –
    list item
    definition list class=class1
    item in a definition list(text=same text)
    describe an item

    list item
    definition list class=class2
    item in a definition list(text=same text)
    describe an item

    definition list class=class3
    item in a definition list(text=other text)
    describe an item
    unordered list class=class3
    list item class=class4
    my link is here with the click function and some text

    i needed to write the html as text – i failed validation when posting the comment…

    I need to activate the link(click).
    I know the classes and the texts.
    any idea how to do it using xpath?
    thanks in advance.

  4. Hi,

    Can you maybe send me the actual html code by email? I can then have a look and see if I can help.

    My email address is ru ‘at’ altom.ro

  5. Hi,

    I have correctly updated the .JS file and packed all content back to .jar file. However when I execute any test case I got following exception in selenium server. Can any one please help me ?

    18:43:42.752 INFO – Command request: getNewBrowserSession[*iehta, http://www.google.com, ] on session null
    18:43:42.756 INFO – creating new remote session
    18:43:43.122 INFO – Allocated session 81c2c3942d2546f2a36b92a4496188a0 for http:
    //www.google.com, launching…
    18:43:43.164 ERROR – Failed to start new browser session, shutdown browser and c
    lear all session data
    java.lang.IllegalArgumentException: Resource not found: /core
    at org.openqa.selenium.server.browserlaunchers.ResourceExtractor.extract
    ResourcePath(ResourceExtractor.java:39)
    at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.create
    HTAFiles(HTABrowserLauncher.java:88)
    at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.launch
    (HTABrowserLauncher.java:63)
    at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.launch
    RemoteSession(HTABrowserLauncher.java:166)
    at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSessi
    on(BrowserSessionFactory.java:372)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession
    (BrowserSessionFactory.java:124)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession
    (BrowserSessionFactory.java:86)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowse
    rSession(SeleniumDriverResourceHandler.java:733)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(Se
    leniumDriverResourceHandler.java:399)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleComman
    dRequest(SeleniumDriverResourceHandler.java:370)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(Selen
    iumDriverResourceHandler.java:129)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)

    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:9
    86)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.
    java:245)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
    18:43:43.226 INFO – Got result: Failed to start new browser session: Error while
    launching browser on session null

  6. Very good work. positive result.

    I’m using it at Windows XP sp3 and testing time decreased to 20% then original.

  7. Hi Jigar,

    I’m not sure what could be wrong with your environment. Here are a few things that come to my mind:

    1. Are you sure you packed the content back correctly? You need to make sure you go *inside* the “seleium-server” folder, select all the files and folders inside it, then archive all of those into “selenium-server.zip”, change that into “selenium-server.jar” and copy it under \Lib\site-packages\SeleniumLibrary\lib\

    2. Does this happen with any browser?

  8. This workaround for IE doesn’t seem to work anymore with Selenium 2.0 (I am using 2.0rc2). When I switched to the 2.0 server and tried to modify it as described in the article it continued to be really slow. Any idea why?

  9. Hi,

    Basically i am into the “Selenium-Server” folder. I can see the bat file inside that.But i am unable to see the “ajaxslt”.
    Please suggest what to do ?

    Thanks

  10. Does this “trick” work with the actual version (2.21.0)? I tried to change to “javascript-xpath” with previous versions and got errors.

  11. It is still working, but it is not possible to extract the files without loosing files. This is due to multiple occurrence of the name “licence”.

    Just extract the file “selenium-browserbot.js”, edit – save exchange the old file with it in the zip-file.

  12. Hi,
    I am also facing the same issue. Using selenium2library with robot framework and running scripts on IE10. Execution speed is very slow.I am not able to locate “selenium-server.jar” file in given folder. Please do the needful.

Leave a Reply

Your email address will not be published. Required fields are marked *