Using Selenium webdriver I have the following element
Is there a way to get all the data- attributes of the element?
For a specific attribute I can use
elem.getAttribute('data-1223')
but how can I get all the data attributes together
解决方案
Use below Code:-
WebElement element = "Your Element"; // Your element
JavascriptExecutor executor = (JavascriptExecutor) driver;
Object aa=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(aa.toString());
Hope it will help you :)