clear()
在这种情况下不起作用。我追加后补充
searchForMovie.clear()
无法正常工作......我也尝试过发送
CTRL + 'a'
,然后是DELETE
。我所得到的只是追加......
for movie in allMissing:
time.sleep (10)
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.send_keys (movie)
# click
enter = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-submit")))
driver.execute_script ("arguments[0].click()", enter)
# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until \
(EC.presence_of_element_located ((By.CSS_SELECTOR, "#search-text")))
searchForMovie.clear()
答案 0 :(得分:3)
要清除文本框,您需要将expected_conditions
设置为element_to_be_clickable
来诱导 WebDriverWait ,然后在 WebElement 上调用click()
然后按如下方式调用clear()
:
# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#search-text")))
searchForMovie.click()
searchForMovie.clear()
答案 1 :(得分:2)
我的案例.clear()
不起作用,您可以尝试:
from selenium.webdriver.common.keys import Keys
#...your code (I was using python 3)
driver.find_element_by_id('foo').send_keys(Keys.CONTROL + "a");
driver.find_element_by_id('foo').send_keys(Keys.DELETE);
答案 2 :(得分:1)
我认为它应该很简单:
driver.execute_script("$('#search-text').val('');")
如果要在不使用jQuery的情况下进行操作,则可以使用普通的javascript:
document.getElementById('search-text').value = '';