Tbody tag in xpath produced by fire bug

百般思念 提交于 2019-12-04 21:34:56

In order to take into account and avoid this problem, use XPath expressions of the following kind:

 /locStep1/locStep2/.../table/YourSubExpression
|
 /locStep1/locStep2/.../table/tbody/YourSubExpression

If the table doesn't have a tbody child, then the second argument of the union operator (|) selects no nodes and the first argument of the union selects the wanted nodes.

Alternatively, if the table has a tbody child, then the first argument of the union operator selects no nodes and the second argument of the union selects the wanted nodes.

The end result: in both cases the wanted nodes are selected

Well with HTML 4 or with XHTML served as text/html the parser always infers a tbody element to wrap tr elements in that are direct children of an table element in the parsed mark up, that is why inside the browser DOM a HTML table always has a tbody containing any tr elements and a tool like Firebug gives you path that works against the Firefox/Mozilla DOM. I don't know what kind of parser your Ruby library uses, perhaps it uses an XML parser for XHTML documents and an XML parser does not infer tbody elements for table elements.

HTML5 always adds the tbody element if its not there explicitly - it's part of the repair strategy for dealing with invalid HTML. If you want to cope with a variety of environments, using table//tr might make sense.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!