定位方式:
- id
- name
- class name
- tag name
- link text 元素文本
- partial link text 元素部分文本
- xpath
- css selector
對應的WebElement/WebDriver方法有:
- 獲取單個WebElement
- find_element_by_id(id_) 等價于下面這個
- find_element(By.ID, id_)
- find_element_by_name(name) 等價于下面這個
- find_element(By.NAME,name)
- find_element_by_class_name(class_name) 等價于下面這個
- find_element(By.CLASS_NAME, class_name)
- find_element_by_tag_name(tag_name) 等價于下面這個
- find_element(By.TAG_NAME, tag_name)
- find_element_by_link_text(link_text) 等價于下面這個
- find_element(By.LINK_TEXT, link_text)
- find_element_by_partial_link_text(link_text) 等價于下面這個
- find_element(By.PARTIAL_LINK_TEXT, link_text)
- find_element_by_xpath(xpath) 等價于下面這個
- find_element(By.XPATH, xpath)
- find_element_by_css_selector(css_selector) 等價于下面這個
- find_element(By.CSS_SELECTOR, css_selector)
- 獲取WebElement 的列表
- find_elements_by_id(id_) 等價于下面這個
- find_elements(By.ID, id_)
- find_elements_by_name(name) 等價于下面這個
- find_elements(By.NAME,name)
- find_elements_by_class_name(class_name) 等價于下面這個
- find_elements(By.CLASS_NAME, class_name)
- find_elements_by_tag_name(tag_name) 等價于下面這個
- find_elements(By.TAG_NAME, tag_name)
- find_elements_by_link_text(link_text) 等價于下面這個
- find_elements(By.LINK_TEXT, link_text)
- find_elements_by_partial_link_text(link_text) 等價于下面這個
- find_elements(By.PARTIAL_LINK_TEXT, link_text)
- find_elements_by_xpath(xpath) 等價于下面這個
- find_elements(By.XPATH, xpath)
- find_elements_by_css_selector(css_selector) 等價于下面這個
- find_elements(By.CSS_SELECTOR, css_selector)
使用時壳繁,根據(jù)自己的喜好自行選擇等價方法。