Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!