zinserjan / wdio-screenshot

A WebdriverIO plugin. Additional commands for taking screenshots with WebdriverIO.
MIT License
109 stars 43 forks source link

Screenshots of fixed elements #48

Open zinserjan opened 7 years ago

zinserjan commented 7 years ago

Screnshots of elements with position: fixed are currently not supported. But it would be nice to support that.

I think this can be done in the following way:

  1. detect if element's position is fixed or if a parent is fixed
  2. if it isn't a fixed element, take the screenshot as usual
  3. when it's fixed, just take a screenshot of the viewport (without css-scroll) and crop it as needed

We coud use a simple script to detect if the element is fixed, like the following:

function isFixed(elem){
  do {
    if (window.getComputedStyle(elem).position == 'fixed') {
      return true;    
    } 
  } while (elem = elem.offsetParent);
  return false;
}