1

I'm running into an issue with Selenium WebDriver in Java, where I can't set the IE browser zoom level to 100% when the user has a different default value. Ctrl + 0 does not work since this sets the zoom to the default. I've tried setting zoom through a JavascriptExecutor, as seen in other posts as well. Any help would be appreciated.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
jonlip
  • 11
  • 1
  • 1
  • 2
  • AFAIK, Selenium doesn't communicates well with `Internet Explorer` until and unless `Zoom Level` is set to `100%`. Any specific business case not to set `Zoom Level` to `100%`? Thanks – undetected Selenium Jul 28 '17 at 13:07
  • I'm using Selenium for a web browser automation application, and running into issues when certain test users have default zoom levels other than 100%, so I need to change it in the code. – jonlip Jul 28 '17 at 13:12
  • 1
    Can you share the specific business case (Testcase) where users have to set zoom levels other than 100%? Thanks – undetected Selenium Jul 28 '17 at 13:17
  • Certain machines that may run my application simply have the zoom level at higher than 100%. I'd rather not force them to change this before using it. There is no specific business case. – jonlip Jul 28 '17 at 13:18
  • I would recommend, before you start your `Automated Test Execution` give yourself time to setup & configure the `Test Environment` first. Successful `Test Execution Result` depends a lot on it. For your reference, [**`here is the link`**](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver) to the guide for IE settings. – undetected Selenium Jul 28 '17 at 13:27

5 Answers5

2

Try ignoring the zoom level all together.

DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true); driver = new InternetExplorerDriver(caps);

You can see others with the zoom issue here: Similar issue

Josh Adams
  • 2,113
  • 2
  • 13
  • 25
1

From what I googled, you can set the default zoom using the registry. I haven't tried this myself but you should be able to grab the user's default setting, change it to 100% (if it's not there already), do your test, and then restore their default setting.

I haven't tried this myself but it looks pretty straightforward.

HKEY_CURRENT_USERS\SOFTWARE\Microsoft\Internet Explorer\Zoom

Set ZoomFactor to 1000x the factor you want, e.g. 125% is 125000

https://support.microsoft.com/en-us/help/2689447/how-to-set-the-zoom-level-in-internet-explorer-9

JeffC
  • 22,180
  • 5
  • 32
  • 55
1

Try this, you can tweak the calculation which returns the current zoom level, I may be wrong at that

from selenium import webdriver

driver = webdriver.Chrome(executable_path='C:\\Automation Projects\\Selenium Server\\chromedriver.exe')

driver.get('Https://www.google.com')

zoom_level = driver.execute_script('return (window.outerWidth / window.innerWidth)')
if zoom_level > 1:
    driver.execute_script("document.body.style.zoom='90%';")
Satish
  • 1,976
  • 1
  • 15
  • 19
  • 1
    This gave me some hope, but didn't work. The page zoom is getting changed, But the browser zoom in browser settings, is still showing the same number.. and selenium still fails to identify elements. If i put browse zoom as 100 and run document.body.style.zoom='10%' only, then it will make the page tiny, still the code will work. because the browse zoom is 100% even now. I think selenium is not bothered about this document zoom. – anandhu Aug 24 '20 at 09:43
1
JavascriptExecutor js =(JavascriptExecutor)driver;
        js.executeScript("document.body.style.zoom='100%'");
a Learner
  • 4,944
  • 10
  • 53
  • 89
0

Try Below Code, It is working code

InternetExplorerOptions capabilities= new InternetExplorerOptions();
            capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
            System.setProperty("webdriver.ie.driver", Constant.drivers + "\\IEDriverServer.exe");
            driver = new InternetExplorerDriver(capabilities);
            driver.manage().window().maximize();
Champ-Java
  • 111
  • 2
  • 13