Python Selenium:为 favorite/unfavorite 按钮查找元素

Python Selenium: find element for favorite/unfavorite button

我正在尝试查找页面上所有尚未被点击的元素,或者 'favorited.'

这是收藏元素的 html:

<a class="button-fave unfavorited-button favorited-button" rel="78853399" alt="Add to favorites">
    <div class="button-spinner"></div>
    <span class="status-text">Favorite</span>
</a>

这是元素未收藏时的 html 代码:

<a class="button-fave unfavorited-button" rel="78853399" alt="Add to favorites">
    <div class="button-spinner"></div>
    <span class="status-text">Favorite</span>
</a>

我试过:

driver.find_element_by_class_name('button-fave unfavorited-button')

但我得到以下信息:

The given selector button-fave unfavorited-button is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Compound class names not permitted

以下有效,但无法区分最喜欢的元素和不最喜欢的元素:

driver.find_element_by_class_name('button-fave') 

您可以找到所有 a 个元素 not having favorited-button class:

driver.find_elements_by_css_selector("a:not(.favorited-button)")