Reputation: 13
I want to ZoomIn
and later ZoomOut
using below code but its not working.
public void ZoomIn()
{
new Actions(driver)
.SendKeys(Keys.Control).SendKeys(Keys.Add)
.Perform();
}
public void ZoomOut()
{
new Actions(driver)
.SendKeys(Keys.Control).SendKeys(Keys.Subtract)
.Perform();
}
Is there any other way - please guide me. Thanks.
Upvotes: 1
Views: 9446
Reputation: 6551
This is a known Chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=667387
Alternatively, you can set the browser's zoom level via JavaScript:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.body.style.zoom='110%'");
Example:
private int ZoomValue = 100;
private int ZoomIncrement = 10;
public void ZoomIn()
{
ZoomValue += ZoomIncrement;
Zoom(ZoomValue);
}
public void ZoomOut()
{
ZoomValue -= ZoomIncrement;
Zoom(ZoomValue);
}
private void Zoom(int level)
{
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(string.Format("document.body.style.zoom='{0}%'", level));
}
Upvotes: 6