Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

346
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda