0

I am using below code in selenium c# to make chrome browser zoom to 100% using javascript.but its not working please help

var js = ((IJavaScriptExecutor)driver);
js.ExecuteScript("document.body.style.zoom = '100%';");
Izzy
  • 6,740
  • 7
  • 40
  • 84
lightcoder
  • 43
  • 1
  • 8

1 Answers1

1

Zoom is a non-standard property, so it's not supported by all browsers. I'd use transform scale instead, which is supported by all browsers.

https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale

You will need to use prefixes for different browsers, see http://shouldiprefix.com/#transforms

.example {
  -webkit-transform: scale(1); /* Ch <36, Saf 5.1+, iOS < 9.2, An =<4.4.4 */
      -ms-transform: scale(1); /* IE 9 */
          transform: scale(1); /* IE 10, Fx 16+, Op 12.1+ */
}

For your chrome use case, you would use:

document.body.style.webkitTransform = 'scale(1)'
skolldev
  • 1,179
  • 9
  • 19