Use this when you want to locate an element by CSS selector syntax.
# find single div element with class item-container.
first_div = driver.find_element_by_css_selector('div.item-container')
# find single img element with class item-image.
first_img = driver.find_element_by_css_selector('img.item-image')
# find multiple div elements with class item-container.
all_item_divs = driver.find_elements_by_css_selector('div.item-container')
# find multiple img elements with class item-container.
all_item_images = driver.find_elements_by_css_selector('img.item-image')
# find multiple div elements with class item-container,
# and img elements with class item-container.
all_item_elements = driver.find_elements_by_css_selector('div.item-container, img.item-image')
W3 Schools CSS Selectors
Chaining Css Selectors
Selenium Python Readthedocs Locating Elements By CSS Selectors
相关问题 更多 >
编程相关推荐