CSS selector and XPath in Selenium Python [closed]

谁说我不能喝 提交于 2020-05-01 06:41:12

问题


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?


回答1:


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

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

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

How about preferring CSS in comparison to xpath?

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

  • CSS Selectors are more elegant, more readable
  • CSS Selectors are faster
  • XPath engines are different in each browser
  • IE does not have a native xpath engine

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

  • Find element by its text
  • Find element from its descendants (if there are no other better methods)
  • Few other rare situations


来源:https://stackoverflow.com/questions/21172756/css-selector-and-xpath-in-selenium-python

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