Selenium Python quick note. If you .send_keys(“5”) then .send_keys(“5”) again, it will populate “55” in the form.

Selenium Python quick note.

Let’s say you have a form that you have to populate. If you execute¬† send_keys(“5”) then send_keys(“5”) again a bit later before submitting form, it will populate “55” in the input field. It will not replace the existing 5 with a new 5. You first have to .clear() to do that.

self.driver.find_element_by_id("myinput").send_keys("5")
self.driver.find_element_by_id("myinput").send_keys("5")

Above example produces “55”

self.driver.find_element_by_id("myinput").send_keys("5")
self.driver.find_element_by_id("myinput").clear()
self.driver.find_element_by_id("myinput").send_keys("5")

Above example produces “5”