Python: Selenium send_keys input value immediately disappearing after input

528 views
Skip to first unread message

Anthony Camarillo

unread,
Sep 23, 2020, 5:03:34 PM9/23/20
to Selenium Users

I am trying to use Selenium(3.141.0) with Carfax but I cannot figure out why my input value is disappearing after input. The browser will open, and the input box (for zip code) will fill with the send_keys value but immediately after it will clear the value. Below is the code I have.

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
PATH = "C:\Program Files (x86)\chromedriver.exe" 
driver = webdriver.Chrome(PATH) 
try: 
     element = driver.find_element_by_name('zip')
     element.send_keys('92880') 
except: 
     driver.quit()

I have also tried

driver.execute_script("arguments[0].value='92880';",element)

but this has the same result.

Anthony Camarillo

unread,
Sep 23, 2020, 5:03:36 PM9/23/20
to Selenium Users
I am trying to use Selenium(3.141.0) with Carfax but I cannot figure out why my input value is disappearing after input. The browser will open, and the input box (for zip code) will fill with the send_keys value but immediately after it will clear the value. Below is the code I have. 

```
from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
PATH = "C:\Program Files (x86)\chromedriver.exe" 
driver = webdriver.Chrome(PATH) driver.get('https://www.carfax.com/UsedHatchbacks_bt4') 

Radhika VISWANATHAN

unread,
Sep 29, 2020, 8:02:42 AM9/29/20
to Selenium Users
Hi Anthony,

You need to add time.sleep(2) which will make your script wait for 2 seconds. In the mean time the page will get fully loaded. In your case the page gets loaded after you set the value...

Hope it help...

ddlionx

unread,
Sep 29, 2020, 8:08:38 AM9/29/20
to seleniu...@googlegroups.com
But what if the page takes 3 seconds?! 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/81d252d4-edeb-48b9-b6fe-fbc26432baa7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages