TestProject Forum
Powered by leading experts in the test automation community

Zoom in on browser with selenium in Java

How can I make the chrome browser zoom in on page?

Is it possible to initiate scroll up with mouse wheel or something similar ?

In Java it is fairly easy:

You have to use the Keys.chord() method:

WebElement page = driver.findElement(By.tagName("html")); page.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));

It’s not working for some reason

Browser window size not changing at all :frowning:

Which browser are you using for the tests ?

It works fine for me in Firefox.
There might be a problem with Chrome though

Yea I am using Chrome.

Getting an error “Failed to send keys because cannot focus element”

Is there a way to get this to work in Chrome? I need to run these tests in Chrome for the time being

Try this:

WebElement body = driver.findElement(By.tagName("body")); body.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));

For some reason it works when trying to focus the body element in DOM, whereas on the html root element it fails… strange. But this works for me in chrome.

This one actually works.

Thanks a lot Dimitri!