要查找您所在的元素:
sixth_item = driver.find_element_by_id("coption5")要仅通过使用 coption 来定位此元素,可以使用以下
定位策略之一:
使用
XPATH
和starts-with()
:sixth_item = driver.find_element_by_xpath("//*[starts-with(@id, 'coption')]")使用
XPATH
和contains()
:sixth_item = driver.find_element_by_xpath("//*[contains(@id, 'coption')]")使用
CSS_SELECTOR
和^
(开头为通配符):sixth_item = driver.find_element_by_css_selector("[id^='coption']")使用
CSS_SELECTOR
和*
(包含通配符):sixth_item = driver.find_element_by_css_selector("[id*='coption']")



