1
I have a situation where I need to rescue values from a array of article
's, however I’m not trying very successfully. My HTML is this way:
<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’t get hold of the next ones because the classes have equal names. See:
WebElement txtArticle;
txtArticle = driver.findElement(By.className("card"));
System.out.print(title.getText());
Return referring to the above code:
Article by Bigown
As I wished to return:
Article by Bigown
Article by Bacco
Article by Wallace
Article by Guilherme
Article by Marcelo
How can I redeem the values of each article
even containing equal classes using Selenium?
Man, take away a doubt. How do I pick up values only within a certain div?
– viana
You can pick up by Xpath, for example if I have
<div id="my_div>
 <a>a1</a>
 <a>a2</a>
 <a>a2</a>
</div>
To catch all the<a>
from inside this div would be something like:List<WebElement> anchors = driver.findElements(By.xpath("//div[@id='my_div']/a"));
In this Xpath it will fetch the div that has the my_div id, after finding it will filter all the Anchors from within this div. Ai with respect to Xpath, you can filter by other attributes tbm, in case if my div has a specific class my Xpath can be//div[@class='my_class']
for example– brow-joe