1、可能沒有定位到改元素上,可以先點擊該元素
driver.find_element_by_xpath(".//*[@id='spellcity']").click()
driver.find_element_by_xpath(".//*[@id='spellcity']").clear()
driver.find_element_by_xpath(".//*[@id='spellcity']").send_keys("嘉興")
2、換種思路,雙擊該元素,選中原來的輸入項
#定位到輸入框元素
inputBox = wait.until(EC.presence_of_element_located((By.XPATH,".//*[@id='spellcity']")))
#雙擊事件
ActionChains(driver).click_and_hold(inputBox).perform()
#輸入內容
inputBox.send_keys("嘉興")
3、萬能的js
js = 'document.querySelector(".//*[@id='spellcity']").value="";'
driver.execute_script(js)
image.png