Difference between text and innerHTML using Selenium

后端 未结 5 1043
闹比i
闹比i 2020-11-22 15:40

Whats the difference between getting text and innerHTML when using selenium. Even though we have text under particular element, when we perform

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 16:12

    For instance,

    Example Text

    .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.

提交回复
热议问题