问题描述
我正在开发一个仅与 IE7 和 IE8 兼容的应用程序.我不知道为什么,但有些人建议在识别 IE 中的元素时使用 CSS over XPath.当我访问 Selenium 官方网站时.我读了消息
I am working on an application which is compatible only with IE7 and IE8. I didn't know why but some suggested to use CSS over XPath while identifying the elements in IE. When I visited the official Selenium site. I read the message
WebDriver 尽可能使用浏览器的原生 XPath 功能.在那些不支持原生 XPath 的浏览器上,我们提供了自己的实现.除非您意识到各种 xpath 引擎之间的差异,否则这可能会导致一些意外行为.
WebDriver uses a browser’s native XPath capabilities wherever possible. On those browsers that don’t have native XPath support, we have provided our own implementation. This can lead to some unexpected behaviour unless you are aware of the differences in the various xpath engines.
我想知道在哪里可以找到各种 xpath 引擎的差异,在哪些情况下我应该使用 CSS,以及如果我使用 IE,我应该在哪些 XPath 中找到.谢谢.
I would like to know where I can find the differences in the various xpath engines and in which situations I should use CSS and and in which XPath specifically if I'm using IE. Thanks.
推荐答案
根据 Ashley Wilson 的 酱实验室的报告:
According to Ashley Wilson's report from sauce labs:
优点:
- 他们更快
- 它们更具可读性
- CSS 是 jQuery 的定位策略
- 反正没有其他人使用 XPATH!
有点过时了,但是这里是数字:
It's a bit outdated, however here are the numbers:
就个人而言,我会争论 (2)-nd 陈述,我必须同意其余的.
Personally, I would argue about (2)-nd statement, I must agree with the rest.
缺点:
- 没有自下而上"的导航.XPath 有
elem..another_elem
- 是否注入了 Sizzle?还是使用了浏览器的 CSS 定位器解析器?取决于浏览器,并且存在不一致.
这篇关于为什么在 IE 中更喜欢使用 CSS 而不是 XPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!