injected text using send_keys() appears for a couple seconds then cleared

39 views
Skip to first unread message

gillijan

unread,
Nov 20, 2022, 11:59:00 PM11/20/22
to Selenium Users
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)
```
example.mov

Adrian

unread,
Nov 22, 2022, 3:32:39 PM11/22/22
to Selenium Users
Hi Gillijan,
Great work on providing a mov!  It's great to see what is happening.

I would like to see an example of a test where it was working, so I can compare the 2 results.

I am thinking that maybe you are entering invalid details into the search, so the program is automatically clearing it.
I see that you are entering the text "Acne vulgaris, mild ".  Maybe your program doesn't like the space at the end and it is clearing the field.
Very hard to tell.

To confirm this, my next step would be to enter the text in manually to see if the same result happens.  
It is very important to enter the exact same text as your test.  So I would copy the exact text (including that extra space) from your test and paste it into you program.
It maybe that the space is a special character that is being rejected.

Once you fixed that issue, then I would improve your xpath.  It looks very fragile.
For example to target the Search Diagnosis input field I would try something like: 
//input[@placeholder="Search diagnosis..."] 


Cheers,
Adrian.

gillijan

unread,
Nov 23, 2022, 7:07:43 PM11/23/22
to Selenium Users
Hi Adrian!

Thank you for the help, after using strip() to remove the extra spaces in each diagnosis the code is running correctly now!

Adrian Tankard

unread,
Nov 23, 2022, 7:12:57 PM11/23/22
to seleniu...@googlegroups.com
Great news!
Now fix those xpath statements, they are horrible!  
If you leave them like I see in your comments, then you will have a hard time maintaining them and your tests will be easily broken.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/Je1J1omuppE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/713164d8-87bf-47fe-b591-bfdd5eddf0e4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages