selenium 中的 send_keys 属性不插入文本,但没有显示错误 (Python)

send_keys attribute in selenium does not insert text, but shows no error (Python)

我尝试在具有属性 send_keys()

的框中插入文本但未成功
driver.get('https://www.carrefour.es/')
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='search-input']"))).send_keys('bolsa')

这是HTML:

<input id="search-input" placeholder="Buscar en todo Carrefour" title="Buscar en Carrefour" type="text" autocomplete="off" readonly="readonly" value="" class="search-input search-box">

我尝试清除输入,使用 xpath、id、css 选择器插入。他们都归结为不显示任何错误,但不显示任何字。

当用户点击搜索输入框时,元素实际上是在变化的。您需要添加明确的等待,然后您应该能够输入文本。我可以在搜索框中输入文字。

driver.get('https://www.carrefour.es/')
searchElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='search-input']")))

#This click should enable to input box

searchElement.click()

# Wait for the element

searchInput = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//*[@inputmode= 'search']")))

searchInput.send_keys("Hi")
driver.find_element_by_xpath("//button[contains(@class,'search-button')]").click()