Using Selenium webdriver I have the following element
This concept works very well. Try this!
WebElement element = driver.findElement(By.tagName("button"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
Object elementAttributes = executor.executeScript("var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;",element);
System.out.println(elementAttributes.toString());