clear() does not clear the textbox with selenium and python and firefox

左心房为你撑大大i 提交于 2020-02-03 10:47:52

问题


clear() does not work in this case. I am getting append after append.
searchForMovie.clear() is not working... I have also tried to send
CTRL + 'a', and then the DELETE. Again all I got are just appends...

 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()

回答1:


To clear the textbox you need to induce WebDriverWait with expected_conditions set to element_to_be_clickable, next invoke click() on the WebElement and then invoke clear() as follows :

# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#search-text")))
searchForMovie.click()
searchForMovie.clear()



回答2:


I think it should be as easy as:

driver.execute_script("$('#search-text').val('');")

If you want to do it without jQuery, you could use plain javascript:

document.getElementById('search-text').value = '';



回答3:


# clear the search text box
searchForMovie = WebDriverWait (driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#search-text")))
searchForMovie.click()
searchForMovie.clear()

I tried this on Instagram Input fields, it is not working.

What i tried doing is:

When the input fails for the "username" and "password" reload the login page "https://www.instagram.com/accounts/login/" using driver.get(url) you will get the fileds cleared.



来源:https://stackoverflow.com/questions/49151508/clear-does-not-clear-the-textbox-with-selenium-and-python-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!