0

I have just migrated my existing code to selenium4.Disable of automation information bar has been made mandate in the latest browser versions so I'm trying to change the zoom level for a particular page through scripting, but it does not seem to work on my machine. I have tried below piece of codes-

1)

JavascriptExecutor jse= (JavascriptExecutor)driver;
jse.executeScript("document.body.style.zoom='90%'");
WebElement html= driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));

Both of them are not working. After trying to evaluate the expression in Intellij during runtime, I'm getting null for the second line of code in the 1st code whereas it is coming as undefined in the second line of code for the 2nd code.

I cannot share the complete code snippet or application image considering I'm working on VDI.

I'm trying to understand the cause of these piece of codes not working on my machine. Has anyone faced a similar issue or knows about this?

Let me know for any more details.

Jagruuti
  • 104
  • 2
  • 14
  • 1
    I just tried code #1 above and it works , Please note that the zoom setting in Chrome will still show 100% even though the page has actually zoomed out. You can test this by increasing the zoom level to 50%, which should make it more obvious that the page has indeed zoomed out. – Abhay Chaudhary Apr 21 '23 at 13:06
  • I just zoomed out to 50% and can see that it has indeed zoomed out. But now for me it appears to be the issue with the screen resolution and display. Thanks for the reply. I will mark this as an answer. Also, can you just copy paste the answer in the Answer section so that I can mark it? – Jagruuti Apr 21 '23 at 14:00
  • Great ! i have added it as an answer below – Abhay Chaudhary Apr 22 '23 at 16:56

1 Answers1

0

I just tried code #1 above and it works , Please note that the zoom setting in Chrome will still show 100% even though the page has actually zoomed out. You can test this by increasing the zoom level to 50%, which should make it more obvious that the page has indeed zoomed out.

JavascriptExecutor jse= (JavascriptExecutor)driver;
jse.executeScript("document.body.style.zoom='50%'");
Abhay Chaudhary
  • 1,763
  • 1
  • 8
  • 13