Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

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

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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...