>>driver.findElement(By.xpath("//div[contains(text(), 'text')]")).getTagName
perhaps, You might have constructed the above xpath by looking into an element of your interest;exists at somewhere in your application. But, There might be a chance of having more than one element matches with your Xpath in the entire DOM Tree.So, Selenium will always returns the element that matches first.As stefan said in the earlier comment use Firepath or xpather add-ons to firefox and search your xpath to see which element(s) the xpath you have constructed being matched.So, correct your xpath so that it would match the element of your interest uniquely.
Also, if you are matching the 'div' element whose text is 'text'. Better, to refine your xpath as.
driver.findElement(By.xpath("//div[text()='text'])).getTagName
Thanks&Regards,
Anjaneyulu P
"The Wa you see is the way you think and is the way you react'
--
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way to react upon!!"