On some web pages, due to rendering issues (e.g., hidden element), WebElement.text
may not reveal the underlying text whereas WebElement.get_attribute("textContent")
will. Therefore I have written the following utility function:
from selenium.webdriver.remote.webelement import WebElementdef text(e: WebElement) -> str: return e.text or e.get_attribute("textContent") or "n/a"
WebElement.get_attribute()
is deprecated in Selenium 4.27.0. The recommendation is to use WebElement.get_dom_attribute()
.
However, this is not a drop-in replacement because WebElement.get_dom_attribute()
will only reveal attributes declared in the HTML markup.
How would I achieve the same functionality without WebElement.get_attribute()
?