clear() 不会清除带有 selenium 和 python 以及 firefox 的文本框
clear() does not clear the textbox with selenium and python and firefox
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()
要清除文本框,您需要在 expected_conditions
设置为 element_to_be_clickable
的情况下引发 WebDriverWait,然后在 [=17] 上调用 click()
=]WebElement 然后调用 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()
我认为它应该像以下一样简单:
driver.execute_script("$('#search-text').val('');")
如果你想在没有 jQuery 的情况下做到这一点,你可以使用普通的 javascript:
document.getElementById('search-text').value = '';
万一.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);
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()
要清除文本框,您需要在 expected_conditions
设置为 element_to_be_clickable
的情况下引发 WebDriverWait,然后在 [=17] 上调用 click()
=]WebElement 然后调用 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()
我认为它应该像以下一样简单:
driver.execute_script("$('#search-text').val('');")
如果你想在没有 jQuery 的情况下做到这一点,你可以使用普通的 javascript:
document.getElementById('search-text').value = '';
万一.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);