GDog
GDog

Reputation: 165

Python Webscrape - Selenium 'CLASS_NAME' - 'not' to include all elements

PYTHON - For Webscraping - is there a way to use Selenium to find an element by CLASS_NAME - but only return the elements under class name 'xxxx' and not elements under class name 'xxxxyy'.

This code returns ALL elements (inclusive) with CLASS_NAME of 'xxxx'.....and includes CLASS_NAME of 'xxxxyy'.

driver.find_elements(By.CLASS_NAME, 'xxxx')

This is my attempt - which returns nothing.

driver.find_elements((By.CLASS_NAME, 'xxxx') and (not(By.CLASS_NAME, 'xxxxyy')))

Thankyou.

Upvotes: 1

Views: 47

Answers (1)

Curious koala
Curious koala

Reputation: 321

Try to use XPath:

driver.find_elements(By.XPATH, "//*[contains(@class, 'xxxx') and not(contains(@class, 'xxxxyy'))]")

Upvotes: 2

Related Questions