I’m facing an issue with my Selenium automation script in Python. Until yesterday, everything was working perfectly. However, today, the script is not behaving as expected.
The problem is with a function that inputs a CPF (Brazilian ID number) into a form field. Although the CPF value is correctly updated in the code, the automation only inputs the first value into the field. When the script tries to enter a new CPF, only the first value is displayed, regardless of the new values being passed.
Here is the relevant part of my code:
def inserir_cpf(self, cpf):
print(f" Inside the Insert CPF function: {cpf}")
campo_cpf = WebDriverWait(self.driver, 10).until(
ec.presence_of_element_located((By.NAME, 'documentNumber'))
)
campo_cpf.clear() # Clears the field before inserting the new value
campo_cpf.send_keys(cpf)
self.simular()
def filtrar_cpf(self):
t = 0
while t < len(doc.dic_cpf):
print(t)
cpf = doc.list_cpf[t]
print('Selecting CPF')
print(cpf)
self.list_banco = ['BMP', 'QI', 'J17']
for i in self.list_banco:
print('Selecting Bank')
print(i)
bot.escolher_banco(i)
bot.inserir_cpf(cpf)
saldo_armazenado = bot.armazenar_saldo(cpf)
if saldo_armazenado:
print('Balance stored')
break
else:
print('Balance not found')
t += 1
Here is an example, the prints show that the values are being updated correctly.
What I’ve Tried
Clearing the field before sending keys:
campo_cpf.clear()
Ensuring the field is clickable:
campo_cpf = WebDriverWait(self.driver, 10).until(
ec.element_to_be_clickable((By.NAME, 'documentNumber'))
)
Inserting value character by character with a delay:
for char in cpf:
campo_cpf.send_keys(char)
time.sleep(0.1)
Ensuring the field is empty before sending keys:
while campo_cpf.get_attribute('value') != '':
campo_cpf.clear()
None of these attempts have resolved the issue. The automation still only inputs the first value into the field.
Additional Information
The field in question is identified by By.NAME, ‘documentNumber’.
The function self.simular() is called after sending keys, but the issue persists even if this function is commented out.
Any insights or suggestions would be greatly appreciated. Thank you in advance!your text
Luis Scarasatti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.