如果以前单击过,如何检查收藏夹按钮? Selenium-Webdriver

How to check a Favorite button, if it is clicked before? Selenium-Webdriver

假设您有一个按钮 ,用于支持某些工作或列表元素。该按钮因为深色和浅色会根据之前是否单击过而改变颜色。

这是我的按钮;

<button class="button button--noshadow button--square job-favorite-button-for-job-2022" onclick="scv.ui.actions.jobs.addFavorite(2022);return false;" data-scv-action-key="favorite" data-scv-action-value="2022">

事情是,如果我可以检查 "data-scv-action-key="favorite" 它是否 = 最喜欢或不最喜欢,我的问题就会得到解决。只是想知道如何使用 Selenium WebDriver 检查 "data-scv-action-key= ?"

//To click on button

    driver.findElement(By.xpath("//button[contains(@classs,'job-favorite-button-for-job-2022')]").click();

//To get the key value

    String actionKey=driver.findElement(By.xpath("//button[contains(@classs,'job-favorite-button-for-job-2022')]")).getAttribute("data-scv-action-key");

//To check the value

    if(actionKey.equals("unfavorite"){
        System.out.println("The button is clicked");
    }
    else{
       System.out.println("The button is clicked");
    }