I am trying to match the text and select the check box.
I am trying to get the text or the innerHTML
from the input tag of type checkbox
.
I tried getText()
; it returns blank, innerHTML
, innerText
returns null
.
I am able to fetch the value, and all the other associated attributes of the tag, but not the text.
I tried getting the text by executing the JavaScript code through Selenium, but that is also returning null
or blank. How can I fix this?
The text is visible - not hidden.
I am trying to match the text and select the check box.
I am trying to get the text or the innerHTML
from the input tag of type checkbox
.
I tried getText()
; it returns blank, innerHTML
, innerText
returns null
.
I am able to fetch the value, and all the other associated attributes of the tag, but not the text.
I tried getting the text by executing the JavaScript code through Selenium, but that is also returning null
or blank. How can I fix this?
The text is visible - not hidden.
Share Improve this question edited Dec 2, 2020 at 13:03 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Dec 5, 2012 at 10:34 vchandevchande 431 silver badge3 bronze badges 4 |2 Answers
Reset to default 19You 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;
}
.getText()
I used.getAttribute("innerHTML")
which will then return what I was looking for, including any HTML that is invisible or text that is hidden. – jsherk Commented Jun 9, 2014 at 16:16