GetText () returns a space in selenium, even if the text is not hidden. Tried javascript as well

I am trying to match text and check the box. I am trying to get text or innerHTML from an input tag of type checkbox . I tried getText() ; it returns empty, innerHTML , innerText returns null . I can get the value and all other related tag attributes, but not text. I tried to get the text by executing a java script through selenium, which also returns null , or is empty could someone help me? The text is visible - not hidden.

+4
source share
2 answers

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

+14
source

public Collection 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; } 
0
source

All Articles