Search code examples
pythonpython-3.xseleniumselenium-chromedriverweb-scripting

How to extract html input value by id with Selenium in Python


How can I extract the value 4 using elementId maxId in Python.

<input type="hidden" id="maxId" value="4">

Python: 3.11.1, ChromeDriver: 109.0.5414.74


Solution

  • Most probably it would be enough to get the value attribute:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    
    driver = webdriver.Chrome(executable_path='path_to_your_driver')
    driver.get("your site")
    // Add wait here
    
    driver.find_element(By.ID, "maxId").get_attribute("value")