0

I have one input box where have numbers, I want to clean it but when call

driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/form/section/div/div/input').clear()

they not remove. If I run same from Python Shell it working. Tried with timeout but can't clear.

I need to sendkeys

driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/form/section/div/div/input').send_keys('50')

Tried

time.sleep(3)
driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/form/section/div/div/input').clear()
time.sleep(3)
driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/form/section/div/div/input').send_keys('50')

and result is 2050

1 Answer 1

1

This seems to be a common problem with newer versions of chromedriver on selenium. I found a hacky solution in just sending a bunch of backspace keys to the selected web element.

for i in range(100):
  WebElement.sendKeys(Keys.BACK_SPACE)

Could even do

for i in range(len(current_field_value)):
  WebElement.sendKeys(Keys.BACK_SPACE)
Sign up to request clarification or add additional context in comments.

3 Comments

for i in range(20): driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/form/section/div/div/input').send_keys(Keys.BACK_SPACE) This working
If the cursor is at the beginning of the field, backspace won't do anything. Where does selenium put the cursor?
Interesting point @JohnGordon [Selenium Docs] (selenium.dev/selenium/docs/api/dotnet/html/…) I found this related to selenium cursor movement, which you could use to move the cursor to the end before backspace. I havent tried to use it in python gonna test it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.