Jump to content

How to set custom zoom in Chrome?


Go to solution Solved by ioa747,

Recommended Posts

Posted

My script opens a particular webpage in Chrome, logs in, then adjusts the window size to the proper location. It then adjusts Zoom using "^_", which works. 

Func StartPage()
   Local $Logon = "xxx"
   Local $Password = "xxx"
    ShellExecute("chrome.exe", "--test-type --ignore-certificate-errors --incognito --app=[URL HERE]")
   Sleep(4000)
   Send ($Logon)
   Sleep(2000)
   Send("{TAB}")
   Sleep(2000)
   Send ($Password, 1)  
   Sleep(2000)
   Send ("{ENTER}")
   WinMove("[Active]", "", 760, -75, 500, 755)
   Sleep(1000)
   send("^-")
   Sleep(1000)
   send("^-")
EndFunc

However, I'm trying to specifically set the zoom level to 80% because currently, if the Chrome page opens at 80% then the code will bring it down to 60%, and etc. 

Is there a way to specify zoom magnification instead of simulating keystrokes?

Posted (edited)

Or you could use WebDriver this way :

#include "wd_core.au3"

Local $sDesiredCapabilities = SetupChrome()
_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://google.com")
_WD_Window($sSession, "MAXIMIZE")
_WD_ExecuteScript($sSession, "document.body.style.zoom='0.8';")

;_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupChrome()
  _WD_Option('Driver', 'chromedriver.exe')
  _WD_Option('Port', 9515)
  _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\chrome.log"')
  ;Return '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"]}}}}'
  Return '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}'
EndFunc   ;==>SetupChrome

Important notice : you cannot have a current opened chrome session when using an existing profile.  Close all Chrome windows before executing this script.

Edited by Nine
Posted (edited)
  On 12/12/2024 at 11:21 PM, Nine said:

you cannot have a current opened chrome session when using an existing profile

Expand  

I think you should create separate profile for yours automation, I mean not using the main chrome profile directory.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...