3

I am facing issues removing readonly tag from an input field using python and selenium. Can anybody help me here?

Datepicker Image:

Datepicker Image

HTML:

<input autocomplete="off" spellcheck="false" type="text" placeholder="Select Date and Time" readonly="readonly" class="ivu-input">

This is the code I am tried to use to remove the tag but the tag is still active during the script is running

a=driver.find_element_by_xpath('//[@id="app"]/div[3]/div/div[3]/div/div/div[2]/div/div/div/div[1]/div[2]/div/div/div/div/input')
driver.execute_script('arguments[0].removeAttribute(\"readonly\")', a);
driver.execute_script('arguments[0].setAttribute("value", "'+dateString+'")', a);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
hkoster
  • 31
  • 1
  • 2

1 Answers1

2

To remove the readonly="readonly" attribute you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.execute_script("arguments[0].removeAttribute('readonly')", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.ivu-input[placeholder='Select Date and Time']"))))
    
  • Using XPATH:

    driver.execute_script("arguments[0].removeAttribute('readonly')", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='ivu-input' and @placeholder='Select Date and Time']"))))
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352