Hi everyone, I came across a problem while working with selenium's send_keys() method. As the subject mentions, the injected text disappears after appearing for a couple of seconds.
(Attached video example)
I've tried using:
- click() before send_keys() to focus on the diagnosis field.
- Waiting until the desired text is present in the element using text_is_present_in_element() to validate the value sent it.
- Also using alternative methods like JsExecutor (driver.execute_script(f"arguments[0].value = {patient.diagnosis[count]};"), elem) to inject text into the text_input field.
Error received
My code receives no errors in regards to finding the element on the screen and raises no exceptions when using send_keys() to inject text.
The block of code also performs the tasks without error for the first 2 patients when using this record_vist() function, however, the outlined block of code stops working because the injected text disappears after a few milliseconds.
Additional Info:
- Using Chrome Version 107.0.5304.110 (Official Build) (x86_64)
- On Mac OS Big Sur Version 11.7
- Using Selenium 4.5.0
HTML Targeted using XPATH
```
<input class="border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm" wire:model.debounce.500ms="search_diagnoses.0" type="text" placeholder="Search diagnosis...">
```
XPATH(//*[@id="919e06c4ea7e2a5bb720134d693a8671"]/div[2]/div[1]/div[2]/div/form/div/div/div[7]/div[2]/input)
div[7] is replaced with {xpath_id[count]} to refer to different text fields.
Block of Code executed (inside record_visit() function)```
index = 0
count = 0
while count < dx_count:
driver.find_element(by=By.CSS_SELECTOR,value="button[class='btn btn-sm btn-secondary font-medium text-sm text-gray-700']").click()
print(f"Current Count {count}")
time.sleep(3)
xpath_id = [7,10,13,16,19]
dx_field = None
dx_field = wait.until(EC.visibility_of_element_located((By.XPATH,f'//*[@id="919e06c4ea7e2a5bb720134d693a8671"]/div[2]/div[1]/div[2]/div/form/div/div/div[{xpath_id[count]}]/div[2]/input')))
print(dx_field)
print(patient.diagnosis[index])
try:
dx_field.send_keys(' ')
dx_field.clear()
ActionChains(driver).move_to_element(dx_field).click().send_keys_to_element(dx_field,patient.diagnosis[index]).perform()
wait.until(EC.text_to_be_present_in_element_value((By.XPATH,f'//*[@id="919e06c4ea7e2a5bb720134d693a8671"]/div[2]/div[1]/div[2]/div/form/div/div/div[{xpath_id[count]}]/div[2]/input'),patient.diagnosis[index]))
except:
driver.refresh()
self.record_visit(patient)
```