I'm trying to create a driver in Selenium 4.10 that will collect all of the performance logs.
The below is what've tried and it doesn't work. From what I've been gathering we need to use the options class to set the logging level as it has replaced the DesiredCapabilities Class. webdriver.Chrome doesn't have an attribute of desired_capabilties.
def get_driver(self):
opts = webdriver.ChromeOptions()
opts.add_argument("--disable-blink-features=AutomationControlled")
opts.add_argument("--ignore-certificate-errors")
opts.add_argument(
f"--user-agent=Lynx: Lynx/2.8.8pre.4 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.23"
)
opts.page_load_strategy = "normal"
service = Service(
service_args=["--log-level=ALL", "--append-log"],
log_path="LOGCHROME.txt",
)
driver = webdriver.Chrome(service=service, options=opts)
driver.execute_cdp_cmd("Performance.enable", {})
return driver
Here is what works with early versions of selenium and what I am trying to recreate:
def get_driver(self):
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
options = webdriver.ChromeOptions()
options.add_argument("headless")
options.add_argument("--ignore-certificate-errors")
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()),
options=options,
desired_capabilities=desired_capabilities,
)
return driver
The reason for me upgrading to a newer version of Selenium, is webdriver_manager chrome has run into a bug where it thinks the driver should be win32. Selenium 4.10 doesn't require the webdriver_manger hence the upgrade.