SendKeys very Slow in Windows Window - c#

I use Selenium with the latest Chromedriver, the Script opens a Windows Window to Select a Picture to Upload.
It's working, but the typing is so slow, like slow-motion 10 Letters > 3-5 Sec....
I use this Command:
SendKeys.SendWait(...);
On the other Side, in the Chrome Window, the SendKeys is so fast, you can't see that is typing, the text is instant here, but not in the Windows Window for Uploading a Pic...
driver.FindElement(By.XPath("...")).SendKeys("...");
Anyone have an Idea why that happens and how I can solve this?

Maybe this will help you
How to handle windows file upload using Selenium WebDriver?
I think
SendKeys.SendWait(...);
is working this way - add a list with letters, then type first, waits when completed and only then adding next one. That why adding more letters will take longer to complete it.
There is Remark from - https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.sendwait?view=windowsdesktop-6.0
Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. You can use this method to send keystrokes to an application and wait for any processes that are started by the keystrokes to be completed. This can be important if the other application must finish before your application can continue.
Your Selenium code:
driver.FindElement(By.XPath("...")).SendKeys("...");
Is adding your full string of text from your "..." to web element.. that why your full text is already in your element. Same as copy and paste.

Related

Selenium ChromeDriver - Run in background but not headless

I am looking for a way to run selenium tests with a chrome driver, in the background. With the background I mean as in, not the foreground focussed window. I can actually do this, but as soon as actions like opening a new tab or switching between windows (so basically switching window handles) happen in the chrome driver, the browser window gets pushed to the foreground.
So my question is, how can I prevent this from happening without running the test headless?
Any suggestions are appreciated, open for discussion.
EDIT
As a somewhat temporary solution I came up with the following.
Using the Windows 10 Virtual Desktops feature, I run the test and thus the chrome browser window in a seperate virual desktop.
I then switch back to my main virtual desktop to continue with other tasks.
This prevents the chrome browser window from being forced to the foreground.
Note that this still makes a flashing chrome icon appear in the taskbar when any of the actions described above appear.
Still looking for a more solid solution, so any suggestions are still appreaciated.
To hopefully open new perspectives and discussion points, and ultimately a solution, I will provide some more detailed info of what my code is doing.
I have 5 chrome webdrivers, and each of these webdrivers contains 6 tabs (WindowHandles).
The idea is that a certain process has to be repeated continuously on each tab. So we loop over each webdriver, and within that webdriver over each tab and set this tab as the webdrivers current WindowHandle. This makes the chrome window visibly switch to the assigned tab.
After that switch has taken place, so basic selenium automation is performed on the content of the tab, after wich we repeat the whole process.
The actual issue seems to take place when a chrome webdriver switches to a new tab (WindowHandle), at this moment the chrome window containing the tab is pushed to the foreground and steals focus. Note that this does not always takes place, often it can switch tabs without any issues. So it is unclear wether there is another factor which would cause the window to steal focus.
EDIT 2
After doing the following:
I overloaded the selenium method which is used to switch between tabs (WindowHandles), and called SetWindoPos each time. Unfortunately this did not solve this issue either. I will try to look deeper into what might be causing this and will report back. – S. Van den Wyngaert
I went out for a few hours while running the tests, and came back to see that surprisingly I was still on my main Virtual Desktop (win10 feature). This means that the issue didn't occur during the time I was gone. I started working again, opened a chrome window and noticed that shortly after I did this, focus was stolen by one of the chrome driver's windows again.
What I conclude from this is that the issue only occurs when another chrome window (not opened by a chrome driver from code) is opened.
I will keep investigating and will report back with updates.
After investigating this behavior for a few more hours I noticed that when another chrome window is open, as long as this has focus, the issue doesn't take place. So to quickly summarize this:
The issue doesn't take place when:
No other chrome windows (not selenium driven) are opened or minimised
Another chrome window (not selenium driven) is opened and has focus
Another application running fullscreen mode has focus
The issue does take place when:
Another chrome window (not selenium driven) is opened and has no focus
Note that when I talk about another chrome window I specificly mean a chrome window that is not driven by selenium, so a regular chrome window opened by the user.
Easiest way would be to run a local selenium grid. Start your node(s) as a windows service. This way the test will run in the background, without being headless.
Another good option to scale your solution, and if your machine has the capacity to run docker, is to use
zalenium
It's a docker based, auto scaling, selenium-grid solution that works pretty quick out of the box.
You can watch your tests live via the management pages, watch a recording after the fact, pause/debug with live interaction via VNC. Also something to be said for not having the worry about changing browser versions.
Last time i used it, it had the odd bug and throws an end of stream error every now and then - but that was a good year ago.

get status info Windows Media Player (stand-alone application)

I want to write an application which gets the status information about a running WMP thread, like playing/paused, shuffle mode on/off, repeat on/off, song title or media file path.
I was using the P/Invoke SendMessage-function to "simulate" a click on the play/pause/stop etc. buttons, but I'm unable read the values of labels/text boxes inside the WMP application with WM_GETTEXT.
I used Spy++ to get the handles of certain text fields - but they (obviously) change their handle after restarting the WMP.
Does somebody know a answer to this Problem?
It could be anything - P/Invoke or SendKeys - but not this AxWindowsMediaPlayer, because my application is a console app and I want the status information of the external process - not of my own.
Thanks
I will mark this thread as 'answered'.
I have solved this problem a few months ago, but lost the source code.
The aim of this application is to control the WMP via sshd or telnet.
You can download the binaries here if you want to:
WMP.rar (27 KB)
https://mega.co.nz/#!ug5DySRR!rQlI9OZZ8wYq7yAqaH-KYsmCl9LSaBjNdvqX0g_WDtI
The application is executed via console. You can see the commands by typing >wmp help

Run a program as a process in the background

I want to create a program that won't close when you click the close button but, only when a exit function is run from within the form.I was thinking i could have it run in the background without the window needing to be open (Like the steam client and dropbox, mediafire, google drive, google chrome extension notification), and was wondering how to do that.
I was thinking of some ways to do it but i wasn't sure how to do them:
A starter program that keeps it open in the background
Running a background process that keeps information stored
I am running c# 2010 so i will need answers relating to that. I would also prefer to not use 3rd party extensions/tools except a basic text editor(Notepad++).Thank you in advance!
There are a number of possible options:
Hide the main form
Create a Tray application
Write a Windows Service

Open process & paste text within this process

I need to Open a process (easy)
and then somehow paste data from my application into this opened application into it's currently active textbox.
How can I get that done?
using the windows clipboard seems like an easy option, if the user can paste manualy, or you control the code for both applications and can make both work with the clipboard
EDIT
Using win 32 api's send message can provide the answer as well, especially if you dont control the code for the process you want to write into, and want it to be 100% automatic.
Check out these links
https://stackoverflow.com/a/4539229/1394380
How to send text to notepad
win 32 api messaging with send message
The general steps for this solution are: to find the text box, using the FindWindow function and then send the text, using the send message. Note: As far as i understand, the receiving application, should yet have a handler for the message and update accordingly

When using SendInput how can I tell when the receiving window has received and processed the messages?

I'm using the Input Simulator library to simulate input to another application using C#, this uses the SendInput API calls. Does anyone know if there is a way I can monitor the windows message queue for the external application to see if those messages have been processed?
For example, let's say I want to send the keystrokes for the word "Hello" to notepad, but I don't want my application to continue until notepad has received and processed the input and the word "Hello" has appeared in the notepad window. We'll know this has happened once the keypress messages are no longer in the message queue for notepad, but I can't work out how to find that out.
I was using the .NET SendKeys class and using SendWait, but this seems unstable and causes occasional freezes in the external application, so after weeks of trying to fix that I'm looking for a new method.
Many thanks
You can't. Calling SendInput ultimately results in posted messages which are delivered asynchronously.
Why fake input to Notepad when you can send the text direct to the edit window? Not only would it be way simpler it would be robust and synchronous.

Categories