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

2024-06-02 09:37:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试查找页面上所有尚未单击或“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') 

Tags: todivadd元素htmlbuttonaltclass