0
<td class="v-grid-cell numerical" style="height: 22px; width: 94px;" colspan="1">32942025</td>

This is my html code relevant to the question. I want to fetch that numeric value 32942025 and validate it with the output of a query I have fired.

I have been using getText() to extract this value but the getText() is not returning anything.

Can anyone please provide me a solution to this?

Note that this integer value is not inside an input field but it is displayed in a td class

jhamon
  • 3,603
  • 4
  • 26
  • 37

1 Answers1

0

To print the text 32942025 from the <td> you can use either of the following locator strategies:

  • Using cssSelector and getAttribute("innerHTML"):

    System.out.println(driver.findElement(By.cssSelector("td.v-grid-cell.numerical")).getAttribute("innerHTML"));
    
  • Using xpath and getText():

    System.out.println(driver.findElement(By.xpath("//td[@class='v-grid-cell numerical']")).getText());
    

Ideally, to extract the text 32942025, you have to induce WebDriverWait for the visibilityOfElementLocated() and you can use either of the following locator strategies:

  • Using cssSelector and getText():

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("td.v-grid-cell.numerical"))).getText());
    
  • Using xpath and getAttribute("innerHTML"):

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[@class='v-grid-cell numerical']"))).getAttribute("innerHTML"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352