In this picture we see we can get styles from copy > copy styles
from chrome manually but is there anyway to do this with selenium
In this link get CSS Value of specific element with selenium but there is no way of doing it for all css rules applied [update: this way is unwanted even it brings all css rules because it doesnt bring dynamic values like 20vw
instead brings hard coded computed values like 240.6px
]
Besides in get all the computed css-styles from a specific dom-element unlike the result(Console Output:
), I cant reproduce the result. for i.e. in page http://loader.to/
if we capture element which has body > div.container > div > div > div:nth-child(3) > label
css selector and put it in elementSelectedWithCssSelector
with the code line of
driver.execute_script('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', elementSelectedWithCssSelector )
we get {'for': 'link'}
but we were supposed to get css rules as the Console Output:
in the SE answer were provided.[update: computed styled always has dynamic values problem mentioned before]
Or with elementSelectedWithCssSelector.get_attribute("style.cssText")
I tried to get styles which returned nothing
[update]: I have tried some approach like Jortega
s answer, but it seems the JS only can bring the computed styles
So my question are (answering one if it is equal to css rules the 'copy > copy styles
from chrome' returns is enough, without dynamic values problem):
- is there any way of automating the
copy > copy styles
from chrome with selenium preferably or other tools? - can it be done with
chrome extension tools
, I mean can I get access to thesecopy > copy styles
with learning how to code an extension for chrome? - [update: unwanted because of computedStyle-dynamicValue problem]or can we get all style rules with the ways were mentioned in the links I have provided here or any other way?
- can we get css rules with
get_attribute
in selenium?