'Selenium fetching Integer value from a TD
<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
Solution 1:[1]
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"));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | undetected Selenium |
