如何让selenium 支持 XML web page

来源:互联网 发布:bt4破解软件下载 编辑:程序博客网 时间:2024/04/30 11:55

通过selenium函数读取XML的web page时,for ex."assertTrue(exceptionCodeManagement.hasText("exceptionCodeList"));", 会提示ERROR: Couldn't access document.body. Is this HTML page fully loaded?

配置完selenium-browserbot.jar后即可以通过selenium读取和验证XML网页了:

 

//转载自 http://www.mernin.com/blog/?p=28

If you are one of the chosen few using (or having to use) the Selenium suite of software test tools, then you may have discovered that it does not natively support XML content. Here is a useful way to modify it so that it does:

  1. Download the latest version in JAR format from your usual Maven repository (e.g. selenium-server-0.9.0.jar)
  2. Unpack this JAR somewhere on your system
  3. $ cd /tmp
    $ mkdir ss090 ; cd ss090
    $ jar xf ~/Desktop/selenium-server-0.9.0.jar

  4. Edit the file /tmp/ss090/core/scripts/selenium-browserbot.js and locate the getBody function (line 1573 approximately)
  5. Modify this function as follows:
  6. PageBot.prototype.bodyText = function() {                     //PageBot即是browserbot
    if (this.getDocument() instanceof XMLDocument) {
    return new XMLSerializer().serializeToString(this.getDocument());
    } else {
    return getText(this.getDocument().body);
    }
    };

  7. Repack the JAR taking care to specify the correct MANIFEST file:
  8. $ cd /tmp/ss090
    $ jar cfm selenium-server-xml-0.9.0.jar META-INF/MANIFEST.MF *

  9. If you want to produce an MD5 signature for this JAR file, you can do so using the md5sum program.
原创粉丝点击