Redeem same named class values using Selenium

1

I have a situation where I need to retrieve values from a array of article 's, but I'm not very successful. My HTML looks like this:

<section class="list">
    <article class="card">
        Article by Bigown
    </article>
    <article class="card">
        Article by Bacco
    </article>
    <article class="card">
        Article by Wallace
    </article>
    <article class="card">
        Article by Guilherme
    </article>
    <article class="card">
        Article by Marcelo
    </article>
</section>

Using JAVA, I can only capture the value of the first <article> passing the class, but I can not get the next ones because the classes have the same names. See:

WebElement txtArticle;
txtArticle = driver.findElement(By.className("card"));
System.out.print(title.getText()); 

Return for the above code:

  

Article by Bigown

As I wanted to return:

  

Article by Bigown

     

Article by Bacco

     

Article by Wallace

     

Article by Guilherme

     

Article by Marcelo

How can I redeem the values of every article even containing equal classes using Selenium?

    
asked by anonymous 28.02.2017 / 21:49

1 answer

3

In fact the problem is in find, in selenium when you use driver.findElement by default it takes the first, in this case you can get driver.findElements for example:

        List<WebElement> txtArticle = driver.findElements(By.className("card"));
        for (WebElement title : txtArticle) {
            System.out.print(title.getText());
        }
    
28.02.2017 / 22:08