var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-333696-1']); _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
  • 2009年08月17日

    Xpath在Selenium中缘何运行MSIE之上慢及对策

    分类:

    Selenium IDE录制时生成测试用例为XHTML文件。而XHTML语言必须符合XML的格式,是XML的一种应用。XPathXML路径语言(XML Path Language),它是一种用来确定XML文档中某部分位置的语言。

     

    见其源码的一例――selenium-ide\trunk\src\content\testSuite.js

    // TODO make this configurable

    TestSuite.header =

        '<?xml version="1.0" encoding="UTF-8"?>\n' +

        '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' +

            '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' +

        "<head>\n" +

        '  <meta c http-equiv="content-type" />' + "\n" +

        "  <title>Test Suite</title>\n" +

        "</head>\n" +

        "<body>\n";

     

    TestSuite.footer =

        "</body>\n</html>\n";

     

    XPath Support in Browsers中写到:
    Microsoft saw fit to build XPath support right into the XML DOM object.

    Firefox supports the XPath according to the DOM standard. A DOM Level 3 addition called DOM Level 3 XPath defines interfaces to use for evaluating XPath expressions in the DOM. Unfortunately, this standard is more complicated than Microsoft's fairly straightforward approach.

    讨论waitForPageToLoad after openWindow中有人写到:
    Generally selenium performance is slow in IE than Firefox.
    Most likely this is because of xpath's performance in IE. Xpath is a lot slower in IE than in Firefox.
    You will speed up your test a lot in IE if you replace xpath with DOM locators or some custom locator that is searching for controls using DOM.

     

    讨论Will selenium.useXpathLibrary(".....")  boost IE performance?和文Selenium IE performance issues; Tests optimization中提及了MSIE中优化Xpath的几种方法。讨论Problem when using waitForPageToLoad in IE!中有人写到:

    XPath as element locator slower in Internet Explorer as there is no native XPath engine available.

    Never, Ever, use Xpath Selectors.

    分享到: