Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
How to change the value of a readonly input dropdown
<input readonly="" value="7 days" style="cursor: pointer;">

This is the only html (no select tag etc.) for the dropdown, which sits within a div.

dropdown

I want to change the value from "7 days" to "Custom date" in my python/selenium script. With a normal input tag, I would have done that:

date = driver.find_element_by_xpath('/html/body/.../div/input') 
date.send_keys('Custom date')

However it doesn't work, because it is readonly. So I tried these two:

driver.execute_script("document.getElementsByTagName('input')[1].removeAttribute('readonly')")
#and send key
driver.execute_script("document.getElementsByTagName('input')[1].setAttribute('7 days', 'Custom Date')")

This didn't work either, so I tried to imitate TAB and ENTER Keys:

date.send_keys(Keys.TAB)
date.send_keys(Keys.TAB)
date.send_keys(Keys.ENTER)

It never did the second TAB and dind't press ENTER either. Nevertheless I think this is the best bet I think since I've seen it work for someone in a video. i would be extremly happy, if you could help me!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok I'm sorry for the lack of description and thanks to you all, the comment of Frenchy got me looking for hours again and I found the problem.

As I said earlier in my question there was simply no way for the value/ key to be sent directly to that input tag. So, as Frenchy suggested I looked further at the HTML code, once I made the dropdown appear.

And there was a div which appeared in the DOM, once the dropdown was there. appearing div Then i copied the xpath and tried to click the span but first when I inspected the element in my normal chrome tab, I got "Message: no such element: Unable to locate element:". Then i did the same in my automated selenium tab and it got me the right xpath. I don't know what the reason for that was (could be ,y own fault), but I thought it might be worth noting.

date = driver.find_element_by_xpath('/html/body/.../div/input')
date.click()
#dropdown appears 
customDate = driver.find_element_by_xpath('/html/body/...div/ul/li[4]/button/div/span')
customDate.click()

This works fine now and makes sense as well, should have seen the appearing div earlier.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda