It gives this error for CSS that exist but do not appear in the site's interface.
My code (site and css are examples):
driver.get("www.example.com")
element = driver.find_element_by_css_selector("css").screenshot_as_png
Error:
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot take screenshot with 0 width."}
but if the link changes, ie tries to take a screenshot from a link where the bodies appear, it works correctly.
what i tried to do is continue without any error. because when it fails, the script stops.
Solution
After some research I found the solution. CODE (site and css are examples):
driver.get("www.example.com")
try:
WebDriverWait(driver, 0).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "css")))
element = driver.find_element_by_css_selector("css").screenshot_as_png
print ("element visible")
except TimeoutException:
print ("element not visible")