css - How to get background-url in Python? -
i trying background url property in python selenium webdriver. works fine 'color' , 'position' properties not 'background' or 'background-url'.
home = driver.find_element_by_id("link-home") print(home.value_of_css_property("position")) => absolute
can me?
this css:
#main-header a#link-home { background: url("data:image/png;base64,ivborw0kggoaaaansuheugaaab8aaaatcayaaabobnzcaaaagxrfwhrtb2z0d2fyzqbbzg9izsbjbwfnzvjlywr5ccllpaaaaofjrefuenpiplrnnqmr4d8qm2ktshuoysaxmbfpmtknlp6fgqlarktfjdgcweary5et5qefa5iisngdio9baao6gimaxx5avbgihac0h66erw3lks0ob2jqvmcdirfb+ehucgatdostghgpksumsa5ycpuho+dw3jx/kbuc2ei0ij4pxmxqpgjpqmizq+xtkhuae5rfoua8e0l+jhj/jha5fgahq7ydgjfkugogbkgxr7iohudkrwe6ojxsog/bkfl/q4myv4nwqsvilwaahvc04ckhafq80hymwj7ylacimadiujmyhco+maaaaabjru5erkjggg==") no-repeat scroll 0px 0px transparent; left: 10px; padding-left: 23px; position: absolute; top: -102px; color: #dfeffc; }
i've reproduced problem getting background
or background-url
property in firefox (using firefox 35.0.1 , selenium 2.45).
workaround worked me in firefox:
print driver.execute_script(""" var element = arguments[0], style = element.currentstyle || window.getcomputedstyle(element, false); return style['background-image']; """, body)
demo:
>>> selenium import webdriver >>> >>> driver = webdriver.firefox() >>> driver.get("http://www.w3schools.com/cssref/tryit.asp?filename=trycss_background") >>> >>> driver.switch_to.frame("iframeresult") >>> >>> body = driver.find_element_by_tag_name("body") >>> >>> print driver.execute_script(""" ... var element = arguments[0], ... style = element.currentstyle || window.getcomputedstyle(element, false); ... ... return style['background-image']; ... """, body) url("http://www.w3schools.com/cssref/smiley.gif")
or, switch webdriver.chrome()
.
Comments
Post a Comment