find_elements_by_class_name(class_name)
find_elements_by_class_name(class_name) finds elements by class name and returns a list with elements if any was found. An empty list if not. It is defined as:
def find_elements_by_class_name(self, name):
"""
Finds elements by class name.
:Args:
- name: The class name of the elements to find.
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_class_name('foo')
"""
warnings.warn("find_elements_by_* commands are deprecated. Please use find_elements() instead")
return self.find_elements(by=By.CLASS_NAME, value=name)
It is worth to be noted that find_elements_by_class_name()
accepts a single class as an argument. Passing multiple classes you will face the error as:
Message: invalid selector: Compound class names not permitted
An example:
tags = driver.find_elements(By.CLASS_NAME, "du4w35lb")
You can find a relevant detailed discussion in Invalid selector: Compound class names not permitted error using Selenium
find_elements_by_xpath(xpath)
find_elements_by_xpath(xpath) finds multiple elements by xpath and returns a list with elements if any was found. An empty list if not. It is defined as:
def find_elements_by_xpath(self, xpath):
"""
Finds multiple elements by xpath.
:Args:
- xpath - The xpath locator of the elements to be found.
:Returns:
- list of WebElement - a list with elements if any was found. An
empty list if not
:Usage:
::
elements = driver.find_elements_by_xpath("//div[contains(@class, 'foo')]")
"""
warnings.warn("find_elements_by_* commands are deprecated. Please use find_elements() instead")
return self.find_elements(by=By.XPATH, value=xpath)
An example:
tags = driver.find_elements(By.XPATH, "//*[@class='du4w35lb k4urcfbm l9j0dhe7 sjgh65i0']")