Selenium Python中的CSS选择器和XPath [英] CSS selector and XPath in Selenium Python

查看:158
本文介绍了Selenium Python中的CSS选择器和XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我没有获得该HTML元素的ID或名称或类,如何在Selenium Python中使用CSS选择器?与XPath相比更喜欢CSS呢?

How about using CSS selector in Selenium Python if I am not getting id or name or class of that HTML element ? How about preferring CSS in comparison to XPath?

推荐答案

不知道您要在这里问什么.我只能猜一猜.

No idea what you are trying to ask here. I can only take a guess.

如果我没有获得ID,如何在Selenium Python中使用CSS选择器 或该html元素的名称或类?

How about using css selector in Selenium Python if I am not getting id or name or class of that html element ?

如果要测试复杂的Web应用程序,则必须学习CSS选择器和/或XPath.是的,其他定位方法受到一定限制.

If you are testing a complex web application, you have to learn CSS Selector and/or XPath. Yes, other locating methods are somewhat limited.

与xpath相比,更喜欢CSS的情况如何?

How about preferring CSS in comparison to xpath?

通常来说,CSS选择器始终支持XPath,因为

Generally speaking, CSS Selectors are always in favor of XPath, because

  • CSS选择器更优雅,更易读
  • CSS选择器更快
  • 每个浏览器中的XPath引擎都不同
  • IE没有本地xpath引擎

但是,在某些情况下,XPath是唯一的选择.例如

However, there are situations XPath is the only way to go. For example

  • 通过文字查找元素
  • 从其后代中查找元素(如果没有其他更好的方法)
  • 其他很少见的情况

这篇关于Selenium Python中的CSS选择器和XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆