Using Playwright for Python, how to I read the content of an input box

In a website I'm automating, I have an input box that is disabled.

On the website it shows a number, like "1" and has other elements to change the value.

<input data-v-a6368fd8="" id="base-amount-input-211" max="10" name="Counter" disabled="disabled" type="number" class="amount-input__number amount-input__number--active">

When I query the element like

handle = page.querySelector('//input[starts-with(@name, "Counter")]')

I get a result for the handle.

When I try readling the handle content

handle.innerText() 

handle.innerHTML()

are both empty ('')

How can I access the current input value?


Another way is to simply use the getAttribute() method of the elementHandle to retrieve the value:

handle = page.querySelector('//input[starts-with(@name, "Counter")]')
value = handle.getAttribute("value")

For input elements, the element.value returns the filled in content. You can use page.evalOnSelector to run JS in the page against this selector and get the value.

selector = '//input[starts-with(@name, "Counter")]'
value = page.evalOnSelector(selector, "(element) => element.value")