Whats the difference between getting text
and innerHTML
when using selenium. Even though we have text under particular element, when we perform
For instance,
.get_attribute("innerHTML")
gives you the actual HTML inside the current element. So theDivElement.get_attribute("innerHTML")
returns "Example Text
"
.text
gives you only text, not include HTML node. So theDivElement.text
returns "Example Text
"
Please note that the algorithm for .text
depends on webdriver of each browser. In some cases such as element is hidden, you might get different text when you use different webdriver.
I usually get text from .get_attribute("innerText")
instead of .text
so I can handle the all the case.