尝试使用 python 删除 html 只读属性

Trying to remove html readonly attribute using python

我正在尝试使用 python 和 selenium 从输入字段中删除只读标签。有人可以帮我吗?

日期选择器图像:

HTML:

<input id="startDate" name="START_DATE" type="text" class="date hasDatepicker" readonly="readonly">

我试过的代码:

driver.execute_script('driver.find_element_by_xpath('"+//*[@id = '"+'startDate'+"']+"').removeAttribute("readonly")')

要删除 readonly 属性,您需要使用 ,如下所示:

element = driver.find_element(By.XPATH, "//input[@class='date hasDatepicker' and @id='startDate']")
driver.execute_script("arguments[0].removeAttribute('readonly')", element)

参考资料

您可以在以下位置找到一些相关的详细讨论: