element positioning
Element positioning is the core of automated testing. If you want to operate an element, you should first identify this element. webdriver provides a series of element positioning methods, commonly used are the following:
- id
- name
- class name
- link text
- partial link text
- tag name
- xpath
- css selector
CSS positioning
Selenium strongly recommends using CSS targeting over XPath targeting. The reason is that CSS positioning is faster than XPath positioning and the syntax is more concise.
CSS common positioning methods
- find_element_by_css_selector()
- #id id selectors locate elements based on the id attribute
- .class class selector, locates elements based on the class attribute
- [attribute='value'] locate elements based on attributes
- element>element locates elements according to the element hierarchy parent element>child element
Case: Searching content through Baidu