Regrettably
unfortunately, achieving this using the standard Selenium API is not feasible.
However, with the help of JavaScript:
You have the option to utilize JavaScript by leveraging Selenium's JavascriptExecutor.executeScript
feature.
The required JavaScript code can be located here and here (as suggested by @Mahsum Akbas)
Below is the Java/Selenium code that will provide you with a string in the format of "css-attribute01:value01; css-attribute02:value02;".
Please note that this will retrieve ALL CSS attributes of the element.
WebElement we = driver.findElement(By.tagName("div"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
String script = "var s = '';" +
"var o = getComputedStyle(arguments[0]);" +
"for(var i = 0; i < o.length; i++){" +
"s+=o[i] + ':' + o.getPropertyValue(o[i])+';';}" +
"return s;";
System.out.println(executor.executeScript(script, we));
You have the flexibility to modify the script based on your requirements. For instance, you could customize it to return only the values without the attributes. Feel free to make changes and experiment.
Update
If you are solely interested in the inline styles of the element, you can utilize the "native" Selenium approach mentioned by @JeffC in the comments:
driver.findElement(By.tagName("div")).getAttribute("style")
However:
Keep in mind that this will only provide you with the "inline styles" and not all the CSS styles applied to the element. Running both versions sequentially and comparing the results will highlight the significant disparity.