getText() returns a blank in Selenium even if the text is not hidden. I also tried JavaScript getText() returns a blank in Selenium even if the text is not hidden. I also tried JavaScript selenium selenium

getText() returns a blank in Selenium even if the text is not hidden. I also tried JavaScript


You could try using getAttribute("textContent") or getAttribute("value")


public Collection<String> getTextValuesFromSearch(WebElement searchContext) {    final Collection<String> collectedText = new ArrayList<>();    final Collection<WebElement> webElementsWithText = searchContext.findElements(By. css/xpath("yourElement"));    for (final WebElement webElement : webElementsWithText) {        collectedText.add(webElement.getText());    }    return collectedText;}