You can get all the products by searching for the div tags that contain the attribute data-content="productItem". That is assuming each item has that attribute. From the screenshots you posted, it seems like that is the case.

You can accomplish this using find_elements_by_xpath()

for item in driver.find_elements_by_xpath('//div[@data-content="productItem"]'):
    ....

This would probably be the best way without having to worry about the elements having different css classes.

Answer from 010011100101 on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › finding items with selenium by css selector using multiple attributes
r/learnpython on Reddit: finding items with selenium by CSS selector using multiple attributes
March 23, 2023 -

Hi all. I'm trying to use Selenium to find an element by CSS selector and although I've tried using the documentation, I think I'm misunderstanding something.

This is what I'm trying:

driver.find_element(By.CSS_SELECTOR,f"img [src='images/icons/new.gif'][alt='Add new item to list']").click()

This is the element I want to find and click:

<img src="images/icons/new.gif" alt="Add new item to list">

The error I get is as follows:

Exception has occurred: NoSuchElementException
Message: no such element: Unable to locate element: {"method":"css selector","selector":"img [src='images/icons/new.gif'][alt='Add new item to list']"}

I can see it's on the page, however, so I'm not sure what I'm missing. I can find other items using XPATH and ID so selenium is up and running, just to rule that out. Can anybody suggest anything?

(I'm using selenium 4.8.2 and python 3.11.1, if that helps)

Discussions

html - How to loop multiple elements in python selenium (different CSS selectors) - Stack Overflow
I am trying to loop inside a class offer-list-wrapper which has multiple elements inside, almost all the elements are common in the web page for search A and search B (I am scraping a crawler). As... More on stackoverflow.com
🌐 stackoverflow.com
March 5, 2020
python - find_element_by_class_name for multiple classes - Stack Overflow
Selenium in the API for Python / Django has the function driver.find_element/elements_by_class_name (), but it is not written whether it can be used for several classes I need choose element with s... More on stackoverflow.com
🌐 stackoverflow.com
Selenium with Python - find elements of more than one css class - Stack Overflow
I need to lookup a list of items that have various css classes, but have them returned in a single list, so I can loop through it, in below case I need to pick up all 4 items. More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
Using CSS selector for find element with multiple class in Selenium in Python - Stack Overflow
I want to find element below with find_elements_by_css_selector(...) but it have multiple class artdeco-modal, artdeco-modal--layer-default ,ip-fuse-limit-alert. I used Selenium IDE for collecting ... More on stackoverflow.com
🌐 stackoverflow.com
February 26, 2021
🌐
TESTEROPS
seleniumwithjavapython.wordpress.com › selenium-with-python › web-elements-locating-mechanisms › handling-multiple-css-selectors
Handling Multiple CSS Selectors - testerops - WordPress.com
July 20, 2016 - """ element5=driver.find_element_by_css_selector("label[class^='class-name1']") print(element5.text) sleep(5) element6=driver.find_element_by_css_selector("label[class$='class-name2']") print(element6.text) sleep(5) element7=driver.find_element_by_css_selector("input[class*='class-name2']") element7.clear() element7.send_keys('narkanda@gmail.com') sleep(5) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
🌐
ScrapeOps
scrapeops.io › home › selenium web scraping playbook › python selenium find elements css
Python Selenium Guide - Finding Elements by CSS Selectors | ScrapeOps
January 8, 2024 - Now that we have a basic understanding of CSS selectors, let's apply this new knowledge. The code example below finds all tag elements on the page. from selenium import webdriver from selenium.webdriver.common.by import By #open an instance of Chrome driver = webdriver.Chrome() #navigate to the page driver.get("https://quotes.toscrape.com") #look for custom elements named "tag" selector = ".tag" #find all elements with this selector elements = driver.find_elements(By.CSS_SELECTOR, selector) #print the text of each element for element in elements: print(element.text) #close the browser driver.quit()
🌐
Python Examples
pythonexamples.org › python-selenium-find-element-by-css-selector
How to find Element by CSS Selector using Selenium Python
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.common.by import By # Setup chrome driver driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install())) # Navigate to the url driver.get('/tmp/selenium/index-52.html') # Find element by CSS Selector my_div = driver.find_element(By.CSS_SELECTOR, 'div.xyz') print(my_div.get_attribute("outerHTML")) # Close the driver driver.quit() ... Now, let us consider the scenario where there are multiple HTML Elements with a match for the given CSS selector string 'div.xyz'.
🌐
Selenium Python
selenium-python.readthedocs.io › locating-elements.html
4. Locating Elements — Selenium Python Bindings 2 documentation
from selenium.webdriver.common.by import By driver.find_element(By.XPATH, '//button[text()="Some text"]') driver.find_elements(By.XPATH, '//button') The attributes available for the By class are used to locate elements on a page. These are the attributes available for By class: ID = "id" NAME = "name" XPATH = "xpath" LINK_TEXT = "link text" PARTIAL_LINK_TEXT = "partial link text" TAG_NAME = "tag name" CLASS_NAME = "class name" CSS_SELECTOR = "css selector"
Find elsewhere
🌐
DevQA
devqa.io › selenium-css-selectors
Selenium CSS Selectors Examples
In the above snippet, we want to select an available day (i.e. the two last div elements) As can be seen, all four divs contain “calendar-day-“ but the first two also contain “unavailable” which we don’t want. The CSS selector for Not selecting the first two divs is · driver.findElement(By.cssSelector("div[class*=calendar-day-]:not([class*='unavailable'])"));" ... There are occasions when there are multiple child elements within the same parent element such as list elements
🌐
Readthedocs
selenium-python-test.readthedocs.io › en › latest › locating-elements.html
4. Locating Elements — Selenium Python Bindings 2 documentation
from selenium.webdriver.common.by import By driver.find_element(By.XPATH, '//button[text()="Some text"]') driver.find_elements(By.XPATH, '//button') ... ID = "id" XPATH = "xpath" LINK_TEXT = "link text" PARTIAL_LINK_TEXT = "partial link text" NAME = "name" TAG_NAME = "tag name" CLASS_NAME = "class name" CSS_SELECTOR = "css selector"
🌐
YouTube
youtube.com › software testing mentor
Selenium CSS Selector #3 - CSS Selector with Multiple Attributes - YouTube
❖ FREE Training's at https://training.rcvacademy.com ❖ In this Selenium CSS selector tutorial we will learn how to write Selenium CSS selector using multiple...
Published   April 2, 2020
Views   549
🌐
GeeksforGeeks
geeksforgeeks.org › locating-multiple-elements-in-selenium-python
Locating multiple elements in Selenium Python - GeeksforGeeks
September 26, 2024 - To check practical Implementation, visit - find_elements_by_class_name() driver method – Selenium Python · Note: command find_elements_by_class_name() is deprecated · With this strategy, all elements with the matching CSS selector will be returned.
🌐
Selenium
selenium.dev › documentation › webdriver › elements › locators
Locator strategies | Selenium
February 16, 2026 - import pytest from selenium import webdriver from selenium.webdriver.common.by import By def test_class_name(): driver = webdriver.Chrome() driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html") element = driver.find_element(By.CLASS_NAME, "information") assert element is not None assert element.tag_name == "input" driver.quit() def test_css_selector(driver): driver = webdriver.Chrome() driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html") element = driver.find_element(By.CSS_SELECTOR, "#fname") assert element is not None assert element.get_
🌐
TutorialsPoint
tutorialspoint.com › home › selenium › selenium webdriver: identify multiple elements
Selenium Webdriver - Identify Multiple Elements
April 7, 2021 - Also, the value entered within the edit box (obtained from the get_attribute method) - Selenium Python gets printed in the console. Once we navigate to a webpage, we have to interact with the webelements available on the page like clicking a link/button, entering text within an edit box, and so on to complete our automation test case. For this, our first job is to identify the elements. We can create a css selector for their identification and utilize the method find_elements_by_css_selector.
🌐
TOOLSQA
toolsqa.com › selenium-webdriver › css-selectors-in-selenium
How to use and create CSS Selectors in Selenium with examples?
Subsequently, we can use them together to create a CSS Selector for locating the web element, as shown below: textarea.form-control[placeholder='Current Address'] ... Then we provided the value of the class attribute. In the end, inside the square bracket, we provided the placeholder attribute and its value. So this way, we can combine various attributes of an HTML element to locate the web element in Selenium uniquely. With the ever-growing new technologies of web development, multiple times, the web pages are created dynamically.
🌐
Stack Overflow
stackoverflow.com › questions › 33855026 › selenium-with-python-find-elements-of-more-than-one-css-class
Selenium with Python - find elements of more than one css class - Stack Overflow
May 24, 2017 - elements = driver.find_elements_by_css_selector(".dropdown") # or elements = driver.find_elements_by_class_name("dropdown") # elements[0] # elements[1] # ...
🌐
Codeloop
codeloop.org › home › how to use css selectors in python selenium
How to Use CSS Selectors in Python Selenium - Codeloop
March 28, 2024 - A: Yes, you can use find_elements_by_css_selector() method to locate multiple elements. This method returns a list of all matching elements found on the page. Q: What types of CSS selectors are available in Python Selenium?
🌐
Makeseleniumeasy
makeseleniumeasy.com › 2017 › 09 › 26 › how-to-locate-web-element-which-has-multiple-class-names
How To Locate Web Element Which Has Multiple Class Names
September 26, 2017 - driver.findElement(By.cssSelector(“.required_field.cityPadRight.ac_input.origin_ac”)).sendKeys(“DELHI”); package SpecialConcepts; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import io.github.bonigarcia.wdm.WebDriverManager; public class ElementWithMultipleClassNames { @Test public void multipleClassnameWithClassNameLocator() { WebDriverManager.chromedriver().setup(); WebDriver driver=new ChromeDriver(); driver.get("https://www.yatra.com/"); driver.findElement(By.className("requi
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - Learn to use CSS Selector in Selenium scripts for your automated tests with five types of CSS Selectors and code snippet examples.
🌐
Stack Overflow
stackoverflow.com › questions › 66383426 › using-css-selector-for-find-element-with-multiple-class-in-selenium-in-python
Using CSS selector for find element with multiple class in Selenium in Python - Stack Overflow
February 26, 2021 - Use any of the css selector. either classname or tagname[attributename='attributevalue'] div.artdeco-modal.artdeco-modal--layer-default.ip-fuse-limit-alert ... div.artdeco-modal.artdeco-modal--layer-default.ip-fuse-limit-alert[aria-labelled...