N
N
Nemo1112019-01-18 10:37:54
Python
Nemo111, 2019-01-18 10:37:54

How to stably enter text into a browser field from code using Python?

Now Selenium is used in my testing program, but at a minimum, i.e. I only get the elements and their attributes. I don’t want to enter text using Selenium, since the pages of what needs to be tested are dynamic, and before entering the received elements, they are stored in the program for a certain time or parsed, i.e. it occurs that the element will already be changed in the browser and text input will not work.
Now I use win32api to enter text from the code into the clipboard, then using cntrl-v pressing emulation, the text is inserted into the desired element (input type) in the browser.
Question: the text from the clipboard is pasted not always but every other time. I could not catch the reason why sometimes it is not inserted. I tried ready-made libraries for working with the clipboard - the result is the same ..
I decided to add functionality to enter text into the field using keystroke emulation, but for this you need to get the layout language and switch it to the desired one, which also does not work.
Questions:
Which option can work stably with the clipboard?
How to switch language using win32api?
Examples:
what works now win32api:
OpenClipboard()
EmptyClipboard()
SetClipboardText(text, CF_UNICODETEXT)
CloseClipboard()
what called to change language and what doesn't work:
int_num = LoadKeyboardLayout('00000419', 1)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question