Selenium webdriver get all the data attributes of an element

前端 未结 3 1786
孤城傲影
孤城傲影 2021-01-20 01:03

Using Selenium webdriver I have the following element

3条回答
  •  广开言路
    2021-01-20 01:21

    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 :)

提交回复
热议问题