This is a continuation from my other post
Using JSoup to get data-code value of a table
I am trying to get the text inside the <span> tags on the table using the cssSelector() method in Selenium webdriver
<table class ="team-list">
<tr data-code="1">
<td>
<span>
Get This Text
</span>
</td>
</tr>
</table>
I have tried the following code, but this will print out the text in all cells for each row, but i only need to get the one inside the <span> tags
WebDriver driver = new FirefoxDriver();
driver.get("http://www.example.com");
List<WebElement> elements = driver.findElements(By.cssSelector("table.team-list td"));
for(WebElement element: elements)
{
System.out.println(element.getText());
}
.team-list td span... u r providing td so it will give text of all tds including those which don't have span also.List<WebElement> elements = driver.findElements(By.cssSelector("table.team-list td > td:nth-of-type(2)"));