Skip to content
Advertisement

What is the difference between getText() and getAttribute() in Selenium WebDriver?

Both are used to get the WebElement value in between tags.

Is my assumption right? If wrong, please elaborate.

Advertisement

Answer

  <input attr1='a' attr2='b' attr3='c'>foo</input>

getAttribute(attr1) you get ‘a’

getAttribute(attr2) you get ‘b’

getAttribute(attr3) you get ‘c’

getText() with no parameter you can only get ‘foo’

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement