LoginSignup
20
26

More than 5 years have passed since last update.

SeleniumのgetText()とgetAttribute()の違い

Posted at

・getText()…指定されたタグ内のテキストを取得する。
タグに囲まれたテキストが欲しければこっち。

・getAttribute(String param)…引数で渡された属性の値を取得する。
value欲しければこっち。

<input id="sample" attr1="aaa" attr2="bbb" attr3="ccc">foo</input>

String test = driver.findElement(By.id("sample").getAttribute(attr1) // "aaa"
String test = driver.findElement(By.id("sample").getAttribute(attr2) // "bbb"
String test = driver.findElement(By.id("sample").getAttribute(attr3) // "ccc"
String test = driver.findElement(By.id("sample").getText // foo

参考先:
http://stackoverflow.com/questions/32307702/difference-b-w-gettext-and-getattribute-in-selenium-webdriver

20
26
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
26