开发者

XPath evaluate kills a script in Chrome

I am running a simple document.evaluate() with a simple XPath expression on this node:

<li class="comment-block"> 
<div class="comment-icon"> 
    <a href="address.com" class="comment-buddy-icon-link">Address</a> 
</div> 
<div class="comment-content"> 
    <p class="comment-head"> 
        <span class="comment-owner"> 
            <span class="comment-author-container">
                <a href="http://some.address.com">Some Address</a>
            </span> 
        </span> 
        <small class="comment-meta"> 
            Some text
        </small> 
    </p> 
    <div class="comment-body"> 
        <p>Some more Text</p> 
    </div> 
</div>
</li>

The XPath string is: div[contains(@class, 'comment-content')]. This works fine in Firefox and breaks in Chrome. There are no exceptions thrown in Chrome, the script simply exits. I don't understand why this would break, the situation seems to be straightforward, select a child div of the li element, whose class is "comment-content".

What is interesting, another XPath string .//div[contains(@class, 'commen开发者_如何学编程t-content')] works fine in Chrome.


If you want to select div direct children of the context node, there's a Webkit bug that I fixed in December: XPath expressions that start with div are treated as syntax errors. The fix is in the Dev Channel build of Chrome (10), but it's not in stable (9). For now, you'll have to use ./div, which means the same thing as div.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜