Override timezone in Playwright and Selenium

Here’s a small example robot that shows how to override browser timezone in Playwright and Selenium:

*** Settings ***
Library           RPA.Browser.Playwright
Library           RPA.Browser.Selenium

*** Tasks ***
Override timezone in Playwright
    New Context    locale=de-DE    timezoneId=Europe/Berlin
    New Page    https://www.time.gov/
    ${text}=    Get Text    css=#myTime
    Log To Console    ${text}

Override timezone in Selenium
    Open Chrome Browser    about:blank    headless=True
    &{locale}=    Create Dictionary    locale=de_DE
    &{timezoneId}=    Create Dictionary    timezoneId=Europe/Berlin
    Execute Cdp    Emulation.setLocaleOverride    ${locale}
    Execute Cdp    Emulation.setTimezoneOverride    ${timezoneId}
    RPA.Browser.Selenium.Go To    https://www.time.gov/
    ${text}=    RPA.Browser.Selenium.Get Text    css=#myTime
    Log To Console    ${text}

1 Like