** ・ getText ()… Get the text in the specified tag. ** ** If you want text surrounded by tags, click here.
** ・ getAttribute (String param)… Get the value of the attribute passed as an argument. ** ** If you want value, this is it.
<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
Reference: http://stackoverflow.com/questions/32307702/difference-b-w-gettext-and-getattribute-in-selenium-webdriver
Recommended Posts