<th>
<span class="firstLanguage">Zeit</span>
</th>
<th>
<span class="firstLanguage">Nach</span>
</th>
<th>
<span class="firstLanguage"> </span>
</th>
<th>
<span class="firstLanguage">Über</span>
</th>
<th>
<span class="firstLanguage">Gleis</span>
</th>
How can I extract the text from span tags in selenium. Is it via classname, but all four class = "firstLanguage"
You can try below snippet.
int count = selenium.getXpathCount("//span[@class='firstLanguage']").intValue();
for(int i =1 ; i <= count ; i ++){
System.out.println(selenium.getText("//span["+i+"]"));
}
This will return you all the span elements defined by the class firstLanguage
and you can iterate the list to take text out of them.
driver.findElement(By.xpath("/html/body/span")).getText();
will display "Zeit"driver.findElement(By.xpath("/html/body/span[2]")).getText();
will display "Nach"
likewise
driver.findElement(By.xpath("/html/body/span[5]")).getText();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With