问题
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