0
votes

I gotta scroll down a list of articles from a Blog until I find a specific article. For that there is a "Load More" button which gives you more and more articles until there's no more articles to load, so the button disappears, it gets disabled (at least thats what I thought).

My idea was to have a "while" loop until the button gets disabled, meanwhile it would check if the requested article showed up:

public void scrollIntoArticle(String title){
        while(loadMoreBtn.isEnabled()){
            for(WebElement article : articlesList){
                if(article.getText().equals(title)){
                    scrollInto(article);
                    hoverAndClick(article);
                    break;
                } else{
                    scrollInto(lastArticle());
                    hoverAndClick(loadMoreBtn);
                }
            }
        }
    } 

However, it keeps getting an error: "waiting for visibility of element". Trying with "isDisplayed" I get the same issue.

So apparently the button never gets "disabled". The only thing that happens to the element is to get a new attribute on HTML: style="display: none;". For Selenium, "isEnabled" is always true, so the loop keeps going, "waiting for visibility of element".

I am stuck, cannot figure out what condition I can use to check if all the articles got loaded up without checking the "Load More" button. Any suggestions? Appreciate the help!

What is the html of the button when it is enabled and disabled?steven01804
Steve is correct, we would need HTML when the button does not have display: none also when it does have display: nonecruisepandey