[Python] How do I update `grid-template-columns` in inline styles using Python and Selenium?

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Python and Selenium to dynamically change the inline CSS of a `<div>` element. Updating `background-color` works fine, but I can't seem to change `grid-template-columns`.

    from selenium import webdriver

    from selenium.webdriver.common.by import By

    driver = webdriver.Chrome()

    driver.get("http://localhost/test.html") # Simple HTML file with a grid div

    grid = driver.find_element(By.ID, "grid")

    driver.execute_script("arguments[0].style.backgroundColor = 'yellow';", grid) # Works

    driver.execute_script("arguments[0].style.gridTemplateColumns = 'auto auto auto';", grid)

    Continue reading...

Compartilhe esta Página