Zoom out the browser

4,213 views
Skip to first unread message

Gangadhar Perineedi

unread,
Nov 13, 2013, 8:32:14 AM11/13/13
to chromedri...@googlegroups.com
I have tried to zoom out the page with following code
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));

This is working fine with Firefox webdriver. But It's not working with Chrome. It throws the following Exception

org.openqa.selenium.WebDriverException: unknown error: cannot focus element (Session info: chrome=28.0.1500.71) (Driver info: chromedriver=2.3,platform=Linux 3.5.0-30-generic x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 53 milliseconds Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:15:02' System info: host: 'vtiger-desktop', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.5.0-30-generic', java.version: '1.7.0_12-ea' Session ID: 918da5187e72caa1e68c49614c187dee Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={chromedriverVersion=2.3}, rotatable=false, locationContextEnabled=true, version=28.0.1500.71, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)

is there any other way to set Zoom level of browser?

Ken Kania

unread,
Nov 13, 2013, 5:21:09 PM11/13/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Have you tried using the body instead?  If that doesn't work, you could try to find a preference for the zoom.


--
You received this message because you are subscribed to the Google Groups "ChromeDriver Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromedriver-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ken Kania

unread,
Nov 15, 2013, 11:11:14 AM11/15/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Ah, yes, even if you can zoom out, there's probably some bugs where we don't handle zoom correctly.  We technically don't support zoom yet.


Why do you want to zoom in/out?


On Fri, Nov 15, 2013 at 5:05 AM, Gangadhar Perineedi <perineedi...@gmail.com> wrote:

Thanks for your quick response. I have tried with body also, thats not working. but I found a workaround using Robot class in java.
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_MINUS);

It can zoom out the browser. But After Zoom out the browser with Robot class, Chrome webdriver is not working as expected. when it is supposed to click on an element,  neither it is clicking the element nor throwing any exception.But its clicking on some other element instead. Can any one explain why it happens

As you said, we may achieve zoom out by setting the preferences of Chrome Webdriver for default zoom level. if it is possible, Please provide the property name of the Default Zoom level to set preference.

To unsubscribe from this group and stop receiving emails from it, send an email to chromedriver-users+unsub...@googlegroups.com.

Gangadhar Perineedi

unread,
Nov 19, 2013, 1:11:23 AM11/19/13
to Ken Kania, chromedri...@googlegroups.com
In some machines(resolution problems or etc), with default zoom 100% is showing web page with zoom in. So that browser can't display some elements( at Right side of the page ). Then driver not able to click on such elements. Currently I can click on those elements by using executeScript method to run javascript. But Automation should do as like a man. A man can click on those elements by zooming out only.

Ken Kania

unread,
Nov 19, 2013, 12:41:51 PM11/19/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
I'm not sure I understand completely.  A few questions for you:

-This only happens on some machines, not all machines, right?
-On those machines where it does happen, the zoom is already 100%, right?
-For a human to be able to click on some elements on these machines, they cannot scroll to the right, but they have to zoom out in order to click it?  This seems like bad user experience.

Thanks
Ken

Ken Kania

unread,
Nov 20, 2013, 11:32:45 AM11/20/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Can you provide a link or a sample html page that demonstrates the problem?  That would be the best step to move this forward.

Ken


On Wed, Nov 20, 2013 at 7:13 AM, Gangadhar Perineedi <perineedi...@gmail.com> wrote:
Yes, exactly you got my point.

Ken Kania

unread,
Nov 21, 2013, 11:48:54 AM11/21/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Thanks for the response.  I think I screenshot might help me understand exactly what you're saying.  Could you take a few and attach them here?

Ken


On Thu, Nov 21, 2013 at 6:34 AM, Gangadhar Perineedi <perineedi...@gmail.com> wrote:
Actual Problem with display settings in Machine, not with WebPage or browser. I am using Ubuntu 12.10.  In Display Settings, size can be set with one option among five options ( 1024x768, 800x600, 848x480, 640x480 , disabled) only. But monitor required size(1366x768) is  bigger than available sizes. If size set to 1024x768, screen looks like zoom in with 110%. So browser also displays the web page like a zoom with 110% but browser level zoom is 100% only . If we want to the see the web page normally we can set zoom 90% in browser level ( this can be done by using CTRL + MINUS). So if we set browser default zoom level to 90%, we can see all web pages normally. Thats why I zooming out the browser in automation. (this can be done in firefox webdriver but not in chrome webdriver)
My actual problem is not related to chrome Webdriver. But I feel that  zoom is also one of the preferable feature to be supported by chrome web driver.
Thank you for quick responses.
Sorry for my English.
 

Ken Kania

unread,
Nov 22, 2013, 2:14:46 PM11/22/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Interesting.  Really, a horizontal scrollbar should appear that lets the user scroll right.  Seems either the website or Chrome is broken.

Regardless, see "Set A Chrome Preference" at https://sites.google.com/a/chromium.org/chromedriver/capabilities

You'll want to set the "profile.per_host_zoom_levels.<yourdomainname>" pref to .8 or something to achieve your desired zoom.


On Fri, Nov 22, 2013 at 11:14 AM, Ken Kania <kka...@google.com> wrote:
Interesting.  Really, a horizontal scrollbar should appear that lets the user scroll right.  Seems either the website or Chrome is broken.

Regardless, see "Set A Chrome Preference" at https://sites.google.com/a/chromium.org/chromedriver/capabilities

You'll want to set the "profile.per_host_zoom_levels.<yourdomainname>" pref to .8 or something to achieve your desired zoom.

Ken



On Thu, Nov 21, 2013 at 11:16 PM, Gangadhar Perineedi <perineedi...@gmail.com> wrote:
When I open the webPage in browser, It displays the web page as like in screenshot1 SamplePage.png.
After Zooming out the page with 90% using CTRL + MINUS, Page will be displayed as like in screenshot2 SamplePageWithZoom90.png. You can see " + " image in screenshot2 only and you can't see that in the screenshot1.
      Again I am mentioning that This is the issue related to Display&Monitor settings in Machine, not with the Chrome browser. You can reproduce it by reducing the resolution size in display Settings of Your Machine, then your Monitor looks like in zoom. So that your browser also displays the Page with zoom.
   
 

Gangadhar Perineedi

unread,
Nov 25, 2013, 8:04:17 AM11/25/13
to Ken Kania, chromedri...@googlegroups.com
Yes. Due to the problem with my webpage, I can't scroll to the right. My dev-team fixed this issue two days back. Now My webpage has two types of views based on resolution. when Resolution is 1024x768, WebPage will display some Elements. when Resolution is 800x600 or lesser than that , webpage will display some other elements instead. please find the attached screenshots for the same.
    I think we can test these two views of the webpage, If webdriver supports Zoom.

I am able to zoom out the browser by setting preferences with following code
       
        System.setProperty("webdriver.chrome.driver", "/home/scott/Downloads/chromedriver");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_zoom_level",  -0.15);
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOptions("prefs", prefs);       
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY,options);
        WebDriver driver = new ChromeDriver(capabilities);

But After zooming out the browser with the above code, It seems to me that still Click is not working as I said earlier.


--

Regards,
Gangadhar
SamplePageWhenResolutionis800x600.png
SamplePageWhenResolutionis1024x768.png

Ken Kania

unread,
Nov 25, 2013, 11:33:28 AM11/25/13
to Gangadhar Perineedi, chromedri...@googlegroups.com
Ah right, thanks for reminding me.  Bug https://code.google.com/p/chromedriver/issues/detail?id=628 is tracking this.

Ken

asmita...@vvdntech.in

unread,
Nov 18, 2016, 7:30:02 AM11/18/16
to ChromeDriver Users

Hey,
Use this if working on chrome
driver.execute_script("document.body.style.zoom='67%'")
This works for chrome and not for firefox.

Reply all
Reply to author
Forward
0 new messages